From 617f7e8b5b88b94d351a99c54f7173a9f5c851d0 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 16 Aug 2019 19:52:54 +0200 Subject: [PATCH 1/3] Fix segment_time_delta value for ffmpeg 4.1 --- .../Playback/BaseStreamingService.cs | 8 ++++---- .../Playback/Hls/DynamicHlsService.cs | 18 +++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 1f78f5afc..cae877979 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -137,10 +137,10 @@ namespace MediaBrowser.Api.Playback /// private string GetOutputFilePath(StreamState state, EncodingOptions encodingOptions, string outputFileExtension) { - var data = GetCommandLineArguments("dummy\\dummy", encodingOptions, state, false); - - data += "-" + (state.Request.DeviceId ?? string.Empty) - + "-" + (state.Request.PlaySessionId ?? string.Empty); + var data = $"{state.MediaPath}-" + + $"{state.UserAgent}" + + $"{state.Request.DeviceId ?? string.Empty}-" + + $"{state.Request.PlaySessionId ?? string.Empty}"; var filename = data.GetMD5().ToString("N", CultureInfo.InvariantCulture); var ext = outputFileExtension.ToLowerInvariant(); diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index fdae59f56..786847821 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -904,7 +904,8 @@ namespace MediaBrowser.Api.Playback.Hls } else { - var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"", + var keyFrameArg = string.Format(" -force_key_frames:0 \"expr:gte(t,{0}+n_forced*{1})\"", + GetStartNumber(state) * state.SegmentLength, state.SegmentLength.ToString(CultureInfo.InvariantCulture)); var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode; @@ -961,10 +962,10 @@ namespace MediaBrowser.Api.Playback.Hls var timeDeltaParam = string.Empty; - if (isEncoding && startNumber > 0) + if (isEncoding && state.TargetFramerate > 0) { - var startTime = state.SegmentLength * startNumber; - timeDeltaParam = string.Format("-segment_time_delta -{0}", startTime); + float startTime = 1 / (state.TargetFramerate.Value * 2); + timeDeltaParam = string.Format("-segment_time_delta {0}", Math.Round(startTime, 3)); } var segmentFormat = GetSegmentFileExtension(state.Request).TrimStart('.'); @@ -973,11 +974,7 @@ namespace MediaBrowser.Api.Playback.Hls segmentFormat = "mpegts"; } - var breakOnNonKeyFrames = state.EnableBreakOnNonKeyFrames(videoCodec); - - var breakOnNonKeyFramesArg = breakOnNonKeyFrames ? " -break_non_keyframes 1" : ""; - - return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} {10} -individual_header_trailer 0{12} -segment_format {11} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"", + return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} {10} -individual_header_trailer 0 -segment_format {11} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"", inputModifier, EncodingHelper.GetInputArgument(state, encodingOptions), threads, @@ -989,8 +986,7 @@ namespace MediaBrowser.Api.Playback.Hls outputPath, outputTsArg, timeDeltaParam, - segmentFormat, - breakOnNonKeyFramesArg + segmentFormat ).Trim(); } } From 15b054be94778abb09d063dc0e85a9993833c493 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sat, 24 Aug 2019 11:17:17 +0200 Subject: [PATCH 2/3] Fix style issues --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 5 +---- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index cae877979..b42e115a7 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -137,10 +137,7 @@ namespace MediaBrowser.Api.Playback /// private string GetOutputFilePath(StreamState state, EncodingOptions encodingOptions, string outputFileExtension) { - var data = $"{state.MediaPath}-" + - $"{state.UserAgent}" + - $"{state.Request.DeviceId ?? string.Empty}-" + - $"{state.Request.PlaySessionId ?? string.Empty}"; + var data = $"{state.MediaPath}-{state.UserAgent}-{state.Request.DeviceId}-{state.Request.PlaySessionId}"; var filename = data.GetMD5().ToString("N", CultureInfo.InvariantCulture); var ext = outputFileExtension.ToLowerInvariant(); diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 786847821..c9ededcfe 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -974,7 +974,8 @@ namespace MediaBrowser.Api.Playback.Hls segmentFormat = "mpegts"; } - return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} {10} -individual_header_trailer 0 -segment_format {11} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"", + return string.Format( + "{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -segment_time {6} {10} -individual_header_trailer 0 -segment_format {11} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"", inputModifier, EncodingHelper.GetInputArgument(state, encodingOptions), threads, From 2e66361482784aca1860461a3c8090a59c3bb6b0 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sat, 24 Aug 2019 11:38:33 +0200 Subject: [PATCH 3/3] Move argument to new line --- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index c9ededcfe..b88a09dd6 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -904,7 +904,8 @@ namespace MediaBrowser.Api.Playback.Hls } else { - var keyFrameArg = string.Format(" -force_key_frames:0 \"expr:gte(t,{0}+n_forced*{1})\"", + var keyFrameArg = string.Format( + " -force_key_frames:0 \"expr:gte(t,{0}+n_forced*{1})\"", GetStartNumber(state) * state.SegmentLength, state.SegmentLength.ToString(CultureInfo.InvariantCulture));