aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNyanmisaka <nst799610810@gmail.com>2024-10-19 14:46:13 +0000
committerGitHub <noreply@github.com>2024-10-19 08:46:13 -0600
commitdf8edaa083232bd0fe45401501186e31d82e9f2e (patch)
tree568665194850403e16c14f5e91fd85115f5cda8e
parentcbd4e070bf86f7b66564fd8ab1c9fbf4274e7a0d (diff)
Fix seeking beyond EOF in HWA transcoding (#12847)
-rw-r--r--MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs9
1 files changed, 9 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index bd5897a84..28f0d1fff 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -2668,6 +2668,7 @@ namespace MediaBrowser.Controller.MediaEncoding
public string GetFastSeekCommandLineParameter(EncodingJobInfo state, EncodingOptions options, string segmentContainer)
{
var time = state.BaseRequest.StartTimeTicks ?? 0;
+ var maxTime = state.RunTimeTicks ?? 0;
var seekParam = string.Empty;
if (time > 0)
@@ -2678,6 +2679,14 @@ namespace MediaBrowser.Controller.MediaEncoding
// This will help subtitle syncing.
var isHlsRemuxing = state.IsVideoRequest && state.TranscodingType is TranscodingJobType.Hls && IsCopyCodec(state.OutputVideoCodec);
var seekTick = isHlsRemuxing ? time + 5000000L : time;
+
+ // Seeking beyond EOF makes no sense in transcoding. Clamp the seekTick value to
+ // [0, RuntimeTicks - 0.5s], so that the muxer gets packets and avoid error codes.
+ if (maxTime > 0)
+ {
+ seekTick = Math.Clamp(seekTick, 0, Math.Max(maxTime - 5000000L, 0));
+ }
+
seekParam += string.Format(CultureInfo.InvariantCulture, "-ss {0}", _mediaEncoder.GetTimeParameter(seekTick));
if (state.IsVideoRequest)