소스 검색

Workaround ffmpeg keyframe seeking for external subtitles

We seek to the exact position of the keyframe for direct stream/remuxing, but FFmpeg seeks to the previous keyframe when the exact time is provided as input. To work around this, add a 0.5 second offset to the seeking time.

Signed-off-by: gnattu <gnattuoc@me.com>
gnattu 1 년 전
부모
커밋
dec2032e13
1개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

+ 7 - 1
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

@@ -2771,7 +2771,13 @@ namespace MediaBrowser.Controller.MediaEncoding
 
             if (time > 0)
             {
-                seekParam += string.Format(CultureInfo.InvariantCulture, "-ss {0}", _mediaEncoder.GetTimeParameter(time));
+                // For direct streaming/remuxing, we seek at the exact position of the keyframe
+                // However, ffmpeg will seek to previous keyframe when the exact time is the input
+                // Workaround this by adding 0.5s offset to the seeking time to get the exact keyframe on most videos.
+                // This will help subtitle syncing.
+                var isHlsRemuxing = state.IsVideoRequest && state.TranscodingType is TranscodingJobType.Hls && IsCopyCodec(state.OutputVideoCodec);
+                var seekTick = isHlsRemuxing ? time + 5000000L : time;
+                seekParam += string.Format(CultureInfo.InvariantCulture, "-ss {0}", _mediaEncoder.GetTimeParameter(seekTick));
 
                 if (state.IsVideoRequest)
                 {