Skip to content

Commit

Permalink
Correctly round to milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
LetsPlentendo-CH committed Feb 8, 2021
1 parent 8be52c6 commit c309375
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion FinalRetimeWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<Label Grid.Row="2" Grid.Column="1" Content="Loads:" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" FontSize="15"/>
<Label x:Name="WLoads" Grid.Row="3" Content="--:--.---" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" FontSize="15"/>
<Label x:Name="Loads" Grid.Row="3" Grid.Column="1" Content="--:--.---" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" FontSize="15"/>
<Label Grid.Row="4" Grid.ColumnSpan="2" Content="Generated with LoadRetimer v1.0.0" HorizontalAlignment="Center" FontSize="10" />
<Label Grid.Row="4" Grid.ColumnSpan="2" Content="Generated with LoadRetimer v1.1.0" HorizontalAlignment="Center" FontSize="10" />
<Button Grid.Row="5" Grid.ColumnSpan="2" Content="Close" Click="Button_Click" />
</Grid>
</Window>
6 changes: 3 additions & 3 deletions FinalRetimeWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public FinalRetimeWindow() {

public FinalRetimeWindow(TimeSpan wloads, TimeSpan loads) {
InitializeComponent();
WLoads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", wloads);
Loads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", loads);
WOLoads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", wloads - loads);
WLoads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(wloads));
Loads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(loads));
WOLoads.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(wloads - loads));
}

private void Button_Click(object sender, RoutedEventArgs e) {
Expand Down
2 changes: 1 addition & 1 deletion Info.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Content="Load Retimer v1.0.0" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" FontSize="25"/>
<Label Content="Load Retimer v1.1.0" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" FontSize="25"/>
<TextBlock Grid.Row="1" HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Padding="2,0,0,0">
Controls:<LineBreak/>
A/D: go back/forwards 1 frame<LineBreak/>
Expand Down
9 changes: 6 additions & 3 deletions LoadInfo.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ private void TryCalculate() {
LoadFrameDurationF.Content = "---";
LoadFrameDurationS.Content = "---";
if (frameStart > -1) {
LoadFrameBeginS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", new TimeSpan((long)(frameStart / MainWindow.frameRate * 10_000_000)));
TimeSpan tmp = new TimeSpan((long)(frameStart / MainWindow.frameRate * 10_000_000));
LoadFrameBeginS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
if (frameEnd > -1) {
LoadFrameEndS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", new TimeSpan((long)(frameEnd / MainWindow.frameRate * 10_000_000)));
TimeSpan tmp = new TimeSpan((long)(frameEnd / MainWindow.frameRate * 10_000_000));
LoadFrameEndS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
if (frameStart > -1 && frameEnd > -1) {
int frameDuration = FrameDuration();
LoadFrameDurationF.Content = String.Format("{0} frames", frameDuration);
LoadFrameDurationS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", new TimeSpan((long)(frameDuration / MainWindow.frameRate * 10_000_000)));
TimeSpan tmp = new TimeSpan((long)(frameDuration / MainWindow.frameRate * 10_000_000));
LoadFrameDurationS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
}

Expand Down
9 changes: 9 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public MainWindow() {
timerAnalyzer.Tick += Analyzer_Tick;
timerAnalyzer.Start();
}

private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) {
if (!Video.IsOpen) return;
if (Video.MediaState == Unosquare.FFME.Common.MediaPlaybackState.Play) {
Expand Down Expand Up @@ -441,4 +442,12 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e) {
}
}
}

class Helper {
public static TimeSpan RoundTimeSpanMillis(TimeSpan ts) {
long ticks = (long) Math.Round(ts.Ticks / 10_000.0) * 10_000;
var res = new TimeSpan(ticks);
return res;
}
}
}

0 comments on commit c309375

Please sign in to comment.