mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-09-01 19:51:28 +02:00
Merge pull request #15 from richardletshacks/main
add basic ffmpeg progress display
This commit is contained in:
@@ -6,7 +6,9 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Flowframes.MiscUtils;
|
||||
|
||||
namespace Flowframes
|
||||
{
|
||||
@@ -65,6 +67,13 @@ namespace Flowframes
|
||||
|
||||
if (line.Contains("No NVENC capable devices found"))
|
||||
Interpolate.Cancel($"FFmpeg Error: {line}\nMake sure you have an NVENC-capable Nvidia GPU.");
|
||||
|
||||
if (line.Contains("time=") && !hidden)
|
||||
{
|
||||
Regex timeRegex = new Regex("(?<=time=).*(?= )");
|
||||
String timestamp = timeRegex.Match(line).Value;
|
||||
UpdateFfmpegProgress(timeRegex.Match(line).Value);
|
||||
}
|
||||
}
|
||||
|
||||
static void FfmpegOutputHandlerSilent (object sendingProcess, DataReceivedEventArgs outLine)
|
||||
@@ -145,6 +154,16 @@ namespace Flowframes
|
||||
return output;
|
||||
}
|
||||
|
||||
public static void UpdateFfmpegProgress(String ffmpegTime)
|
||||
{
|
||||
long total = Program.mainForm.currInDuration / 100;
|
||||
if (total == 0) return;
|
||||
long current = FormatUtils.MsFromTimestamp(ffmpegTime);
|
||||
int progress = Convert.ToInt32(current / total);
|
||||
Program.mainForm.SetProgress(progress);
|
||||
}
|
||||
|
||||
|
||||
public static async Task RunGifski(string args, LogMode logMode)
|
||||
{
|
||||
lastOutputGifski = "";
|
||||
|
||||
@@ -348,6 +348,15 @@ namespace Flowframes
|
||||
}
|
||||
}
|
||||
|
||||
public static long GetDuration(string inputFile)
|
||||
{
|
||||
Logger.Log("Reading Duration using ffprobe.", true, false, "ffprobe");
|
||||
string args = $" -v panic -select_streams v:0 -show_entries format=duration -of csv=s=x:p=0 -sexagesimal {inputFile.Wrap()}";
|
||||
string info = AvProcess.GetFfprobeOutput(args);
|
||||
return FormatUtils.MsFromTimestamp(info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static float GetFramerate(string inputFile)
|
||||
{
|
||||
Logger.Log("Reading FPS using ffmpeg.", true, false, "ffmpeg");
|
||||
|
||||
@@ -15,6 +15,7 @@ using HTAlt.WinForms;
|
||||
using Flowframes.Data;
|
||||
using Microsoft.WindowsAPICodePack.Taskbar;
|
||||
using System.Threading.Tasks;
|
||||
using Flowframes.MiscUtils;
|
||||
|
||||
namespace Flowframes
|
||||
{
|
||||
@@ -119,11 +120,13 @@ namespace Flowframes
|
||||
public Size currInRes;
|
||||
public float currInFps;
|
||||
public int currInFrames;
|
||||
public long currInDuration;
|
||||
public void UpdateInputInfo ()
|
||||
{
|
||||
string str = $"Resolution: {(!currInRes.IsEmpty ? $"{currInRes.Width}x{currInRes.Height}" : "Unknown")} - ";
|
||||
str += $"Framerate: {(currInFps > 0f ? $"{currInFps.ToStringDot()} FPS" : "Unknown")} - ";
|
||||
str += $"Frame Count: {(currInFrames > 0 ? $"{currInFrames} Frames" : "Unknown")}";
|
||||
str += $"Frame Count: {(currInFrames > 0 ? $"{currInFrames} Frames" : "Unknown")} - ";
|
||||
str += $"Duration: {(currInDuration > 0 ? $"{FormatUtils.MsToTimestamp(currInDuration)}" : "Unknown")}";
|
||||
inputInfo.Text = str;
|
||||
}
|
||||
|
||||
@@ -132,6 +135,7 @@ namespace Flowframes
|
||||
currInRes = new Size();
|
||||
currInFps = 0;
|
||||
currInFrames = 0;
|
||||
currInDuration = 0;
|
||||
}
|
||||
|
||||
void InitAis()
|
||||
|
||||
@@ -442,5 +442,10 @@ namespace Flowframes.Main
|
||||
foreach (string frame in sceneFramesToDelete)
|
||||
IOUtils.TryDeleteIfExists(Path.Combine(sceneFramesPath, frame + ".png"));
|
||||
}
|
||||
|
||||
public static void UpdateVideoDuration(string path)
|
||||
{
|
||||
Program.mainForm.currInDuration = FFmpegCommands.GetDuration(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,22 @@ namespace Flowframes.MiscUtils
|
||||
return Time(elapsedMs);
|
||||
}
|
||||
|
||||
public static long MsFromTimestamp(String timestamp)
|
||||
{
|
||||
string[] values = timestamp.Split(':');
|
||||
int hours = Int32.Parse(values[0]);
|
||||
int minutes = Int32.Parse(values[1]);
|
||||
int seconds = Int32.Parse(values[2].Split('.')[0]);
|
||||
int milliseconds = Int32.Parse(values[2].Split('.')[1].Substring(0, 2)) * 10;
|
||||
long ms = hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds;
|
||||
return ms;
|
||||
}
|
||||
|
||||
public static String MsToTimestamp(long milliseconds)
|
||||
{
|
||||
return (new DateTime(1970, 1, 1)).AddMilliseconds(milliseconds).ToLongTimeString();
|
||||
}
|
||||
|
||||
public static string Ratio(long numFrom, long numTo)
|
||||
{
|
||||
float ratio = ((float)numTo / (float)numFrom) * 100f;
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace Flowframes.UI
|
||||
|
||||
Program.mainForm.currInFps = fps;
|
||||
Program.mainForm.currInFrames = frameCount;
|
||||
InterpolateUtils.UpdateVideoDuration(path);
|
||||
Program.mainForm.UpdateInputInfo();
|
||||
CheckExistingFolder(path, outputTbox.Text.Trim());
|
||||
await Task.Delay(10);
|
||||
|
||||
Reference in New Issue
Block a user