Skip to content

Commit

Permalink
Fix: Audio Encoding Progress not shown
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed May 26, 2022
1 parent 6e9ed1c commit 8559358
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NotEnoughAV1Encodes/Audio/EncodeAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Encode(Queue.QueueElement queueElement, CancellationToken _token)
StreamReader sr = processAudio.StandardError;
while (!sr.EndOfStream)
{
int processedFrames = Global.GetTotalFramesProcessed(sr.ReadLine());
int processedFrames = Global.GetTotalTimeProcessed(sr.ReadLine(), queueElement);
if (processedFrames != 0)
{
queueElement.Progress = Convert.ToDouble(processedFrames);
Expand Down
32 changes: 32 additions & 0 deletions NotEnoughAV1Encodes/resources/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ public static int GetTotalFramesProcessed(string stderr)
return 0;
}

public static int GetTotalTimeProcessed(string stderr, Queue.QueueElement queue)
{
try
{
if (stderr.Contains("time="))
{
// Get Timespan of Video
TimeSpan length = TimeSpan.Parse(queue.VideoDB.MIDuration);

// Parse stderr Output of FFmpeg
int Start, End;
Start = stderr.IndexOf("time=", 0) + "time=".Length;
End = stderr.IndexOf("bitrate=", Start);
string ffmpegTime = stderr[Start..End];

// Convert FFmpeg time to Timespan
TimeSpan ts = TimeSpan.Parse(ffmpegTime);

// Progress in Percent
double prog = Math.Round(ts / length, 2) * 100;

// Convert Progress to amount of Frames (roughly)
int frameCount = Convert.ToInt32(prog) * (Convert.ToInt32(queue.VideoDB.MIFrameCount) / 100);

return frameCount;
}
}
catch { }

return 0;
}

private static readonly ReaderWriterLockSlim readWriteLock = new();
public static void Logger(string logMessage, string logPath)
{
Expand Down

0 comments on commit 8559358

Please sign in to comment.