Skip to content

Commit

Permalink
Add Estimated FPS and Estimated Time of Arrival
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Dec 19, 2021
1 parent f23df42 commit 7c43db1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
15 changes: 10 additions & 5 deletions NotEnoughAV1Encodes/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
Expand All @@ -938,20 +939,24 @@
<ColumnDefinition Width="90" />
<ColumnDefinition MinWidth="50"/>
<ColumnDefinition Width="90" />
<ColumnDefinition MinWidth="50"/>
<ColumnDefinition MinWidth="50"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{lex:Loc LabelVideoSource1}" FontWeight="Bold"></Label>
<Label Grid.Column="1" Content="{Binding VideoDB.InputFileName}" ToolTip="{Binding Input}"></Label>
<Label Grid.Column="2" Content="{lex:Loc LabelVideoDestination1}" FontWeight="Bold"></Label>
<Label Grid.Column="3" Content="{Binding VideoDB.OutputFileName}" ToolTip="{Binding Output}"></Label>
<Label x:Name="LabelStatus" Grid.Column="4" Content="{lex:Loc LabelStatus}" FontWeight="Bold"></Label>
<Label Grid.Column="5" Content="{Binding Status}"></Label>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition MinWidth="100"/>
</Grid.ColumnDefinitions>
<Label x:Name="LabelStatus" Grid.Column="0" Content="{lex:Loc LabelStatus}" FontWeight="Bold"></Label>
<Label Grid.Column="1" Content="{Binding Status}"></Label>
</Grid>
<Grid Grid.Row="2">
<ProgressBar Value="{Binding Progress}" Maximum="{Binding FrameCount}"/>
</Grid>
<Grid Grid.Row="1" Visibility="{Binding TwoProgressbars, Converter={StaticResource b2v}}">
<Grid Grid.Row="2" Visibility="{Binding TwoProgressbars, Converter={StaticResource b2v}}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
Expand Down
33 changes: 27 additions & 6 deletions NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,9 @@ private async Task MainStartAsync(CancellationToken _cancelToken)
await Task.Run(() => queueElement.GetVFRTimeStamps(), _cancelToken);

// Starts "a timer" for eta / fps calculation
DateTime startTime = DateTime.Now;
System.Timers.Timer aTimer = new();
aTimer.Elapsed += (sender, e) => { UpdateProgressBar(queueElement); };
aTimer.Elapsed += (sender, e) => { UpdateProgressBar(queueElement, startTime); };
aTimer.Interval = 1000;
aTimer.Start();

Expand Down Expand Up @@ -1589,8 +1590,9 @@ private async Task MainStartAsync(CancellationToken _cancelToken)
Shutdown();
}

private static void UpdateProgressBar(Queue.QueueElement queueElement)
private static void UpdateProgressBar(Queue.QueueElement queueElement, DateTime startTime)
{
TimeSpan timeSpent = DateTime.Now - startTime;
long encodedFrames = 0;
long encodedFramesSecondPass = 0;

Expand Down Expand Up @@ -1621,12 +1623,31 @@ private static void UpdateProgressBar(Queue.QueueElement queueElement)
// Progress 2nd-Pass of 2-Pass Encoding
queueElement.ProgressSecondPass = Convert.ToDouble(encodedFramesSecondPass);

// Divide by 2
try { encodedFrames /= 2; } catch { }
try { encodedFramesSecondPass /= 2; } catch { }
string estimatedFPS1stPass = "";
string estimatedFPS2ndPass = "";
string estimatedTime1stPass = "";
string estimatedTime2ndPass = "";
if (encodedFrames != queueElement.FrameCount)
{
estimatedFPS1stPass = " - ~" + Math.Round(encodedFrames / timeSpent.TotalSeconds, 2).ToString() + "fps";
estimatedTime1stPass = " - ~" + Math.Round(((timeSpent.TotalSeconds / encodedFrames) * (queueElement.FrameCount - encodedFrames)) / 60, MidpointRounding.ToEven) + LocalizedStrings.Instance["QueueMinLeft"];
}

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

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

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

#endregion
Expand Down
27 changes: 27 additions & 0 deletions NotEnoughAV1Encodes/resources/lang/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions NotEnoughAV1Encodes/resources/lang/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,18 @@
<data name="ProgramSettings" xml:space="preserve">
<value>Settings</value>
</data>
<data name="Queue1stPass" xml:space="preserve">
<value>1st Pass:</value>
</data>
<data name="Queue2ndPass" xml:space="preserve">
<value>2nd Pass:</value>
</data>
<data name="QueueMenuItemEdit" xml:space="preserve">
<value>Edit</value>
</data>
<data name="QueueMinLeft" xml:space="preserve">
<value>min left</value>
</data>
<data name="Resume" xml:space="preserve">
<value>Resume</value>
</data>
Expand Down

0 comments on commit 7c43db1

Please sign in to comment.