Skip to content

Commit

Permalink
Make ETA more a bit more reliable after restart #134
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Feb 18, 2023
1 parent d53e2e1 commit c8d009b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 14 additions & 8 deletions NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ private async Task MainStartAsync(CancellationToken _cancelToken)
await Task.Run(() => queueElement.GetVFRTimeStamps(), _cancelToken);

// Start timer for eta / fps calculation
DateTime startTime = DateTime.Now;
DateTime startTime = DateTime.Now - queueElement.TimeEncoded;
System.Timers.Timer aTimer = new();
aTimer.Elapsed += (sender, e) => { UpdateProgressBar(queueElement, startTime); };
aTimer.Interval = 1000;
Expand Down Expand Up @@ -2622,7 +2622,7 @@ private async Task MainStartAsync(CancellationToken _cancelToken)
#region Progressbar
private static void UpdateProgressBar(Queue.QueueElement queueElement, DateTime startTime)
{
TimeSpan timeSpent = DateTime.Now - startTime;
queueElement.TimeEncoded = DateTime.Now - startTime;
long encodedFrames = 0;
long encodedFramesSecondPass = 0;

Expand Down Expand Up @@ -2660,26 +2660,32 @@ private static void UpdateProgressBar(Queue.QueueElement queueElement, DateTime

if (encodedFrames != queueElement.FrameCount)
{
estimatedFPS1stPass = " - ~" + Math.Round(encodedFrames / timeSpent.TotalSeconds, 2).ToString("0.00") + "fps";
estimatedTime1stPass = " - ~" + Math.Round(((timeSpent.TotalSeconds / encodedFrames) * (queueElement.FrameCount - encodedFrames)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
estimatedFPS1stPass = " - ~" + Math.Round(encodedFrames / queueElement.TimeEncoded.TotalSeconds, 2).ToString("0.00") + "fps";
estimatedTime1stPass = " - ~" + Math.Round(((queueElement.TimeEncoded.TotalSeconds / encodedFrames) * (queueElement.FrameCount - encodedFrames)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
}

if(encodedFramesSecondPass != queueElement.FrameCount)
{
estimatedFPS2ndPass = " - ~" + Math.Round(encodedFramesSecondPass / timeSpent.TotalSeconds, 2).ToString("0.00") + "fps";
estimatedTime2ndPass = " - ~" + Math.Round(((timeSpent.TotalSeconds / encodedFramesSecondPass) * (queueElement.FrameCount - encodedFramesSecondPass)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
estimatedFPS2ndPass = " - ~" + Math.Round(encodedFramesSecondPass / queueElement.TimeEncoded.TotalSeconds, 2).ToString("0.00") + "fps";
estimatedTime2ndPass = " - ~" + Math.Round(((queueElement.TimeEncoded.TotalSeconds / encodedFramesSecondPass) * (queueElement.FrameCount - encodedFramesSecondPass)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
}

queueElement.Status = LocalizedStrings.Instance["Queue1stPass"] + " " + ((decimal)encodedFrames / queueElement.FrameCount).ToString("00.00%") + estimatedFPS1stPass + estimatedTime1stPass + " - " + LocalizedStrings.Instance["Queue2ndPass"] + " " + ((decimal)encodedFramesSecondPass / queueElement.FrameCount).ToString("00.00%") + estimatedFPS2ndPass + estimatedTime2ndPass;
}
else
{
// 1 Pass encoding
string estimatedFPS = " - ~" + Math.Round(encodedFrames / timeSpent.TotalSeconds, 2).ToString("0.00") + "fps";
string estimatedTime = " - ~" + Math.Round(((timeSpent.TotalSeconds / encodedFrames) * (queueElement.FrameCount - encodedFrames)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
string estimatedFPS = " - ~" + Math.Round(encodedFrames / queueElement.TimeEncoded.TotalSeconds, 2).ToString("0.00") + "fps";
string estimatedTime = " - ~" + Math.Round(((queueElement.TimeEncoded.TotalSeconds / encodedFrames) * (queueElement.FrameCount - encodedFrames)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];

queueElement.Status = "Encoded: " + ((decimal)encodedFrames / queueElement.FrameCount).ToString("00.00%") + estimatedFPS + estimatedTime;
}

try
{
File.WriteAllText(Path.Combine(Global.AppData, "NEAV1E", "Queue", queueElement.VideoDB.InputFileName + "_" + queueElement.UniqueIdentifier + ".json"), JsonConvert.SerializeObject(queueElement, Formatting.Indented));
}
catch { }
}


Expand Down
2 changes: 2 additions & 0 deletions NotEnoughAV1Encodes/Queue/QueueElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public string Status
public long FrameCount { get; set; }
/// <summary>Date Added to Queue.</summary>
public DateTime DateAdded { get; set; } = DateTime.Now;
/// <summary>Amount of already encoded time.</summary>
public TimeSpan TimeEncoded { get; set; } = TimeSpan.Zero;
/// <summary>List of Progress of each Chunk.</summary>
public List<ChunkProgress> ChunkProgress { get; set; } = new();
/// <summary>State of UI Settings</summary>
Expand Down

0 comments on commit c8d009b

Please sign in to comment.