diff --git a/src/libse/Common/TimeCode.cs b/src/libse/Common/TimeCode.cs index a6dc9d030..c520a893d 100644 --- a/src/libse/Common/TimeCode.cs +++ b/src/libse/Common/TimeCode.cs @@ -347,5 +347,27 @@ namespace Nikse.SubtitleEdit.Core.Common return ToShortString(true); } + + /// + /// Align time to frame rate. + /// + public TimeCode AlignToFrame() + { + var ts = TimeSpan.FromMilliseconds(Math.Round(TotalMilliseconds, MidpointRounding.AwayFromZero)); + var frames = Math.Round(ts.Milliseconds / (TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate)); + TimeSpan ts2; + if (frames >= Configuration.Settings.General.CurrentFrameRate - 0.001) + { + ts = ts.Add(new TimeSpan(0, 0, 1)); + ts2 = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds, 0); + } + else + { + var ms = SubtitleFormat.FramesToMillisecondsMax999(SubtitleFormat.MillisecondsToFramesMaxFrameRate(ts.Milliseconds)); + ts2 = new TimeSpan(ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ms); + } + + return new TimeCode(ts2.TotalMilliseconds); + } } } diff --git a/src/ui/Controls/VideoPlayerContainer.cs b/src/ui/Controls/VideoPlayerContainer.cs index bbb35972b..1c38da512 100644 --- a/src/ui/Controls/VideoPlayerContainer.cs +++ b/src/ui/Controls/VideoPlayerContainer.cs @@ -2023,14 +2023,20 @@ namespace Nikse.SubtitleEdit.Controls { if (VideoPlayer != null) { + var v = value; + if (SmpteMode) { - VideoPlayer.CurrentPosition = value * 1.001; + v *= 1.001; } - else + + if (Configuration.Settings.General.UseTimeFormatHHMMSSFF) { - VideoPlayer.CurrentPosition = value; + var tc = TimeCode.FromSeconds(v); + v = tc.AlignToFrame().TotalSeconds; ; } + + VideoPlayer.CurrentPosition = v; } else { diff --git a/src/ui/Logic/VideoPlayers/LibMpvDynamic.cs b/src/ui/Logic/VideoPlayers/LibMpvDynamic.cs index ae57320ef..dcc940c78 100644 --- a/src/ui/Logic/VideoPlayers/LibMpvDynamic.cs +++ b/src/ui/Logic/VideoPlayers/LibMpvDynamic.cs @@ -241,7 +241,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers _pausePosition = value; } - DoMpvCommand("seek", value.ToString(CultureInfo.InvariantCulture), "absolute"); + DoMpvCommand("seek", value.ToString(CultureInfo.InvariantCulture), "absolute", "exact"); } } } @@ -740,6 +740,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("keep-open"), GetUtf8Bytes("always")); // don't auto close video _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("no-sub"), GetUtf8Bytes(string.Empty)); // don't load subtitles (does not seem to work anymore) _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("sid"), GetUtf8Bytes("no")); // don't load subtitles + _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("hr-seek"), GetUtf8Bytes("yes")); // don't load subtitles if (videoFileName.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || videoFileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase))