diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-03-28 11:22:05 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-03-28 11:22:05 -0400 |
| commit | a59d1f4f70a20eda164814ecb776eaf07ad02435 (patch) | |
| tree | a72564c0299d3ab4f3e09767694f2bde1c39da8b | |
| parent | 8b9d333608b18dfde8278df30a90dfc9daeb42ff (diff) | |
added keyframes to progressive streaming
| -rw-r--r-- | MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/Progressive/VideoService.cs | 62 |
3 files changed, 35 insertions, 36 deletions
diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 600412986..b1879b8d2 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -178,9 +178,7 @@ namespace MediaBrowser.Api.Playback.Hls var probeSize = Kernel.Instance.FFMpegManager.GetProbeSizeArgument(state.Item); - const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+5))"; - - return string.Format("{0} {1} -i {2}{3} -threads 0 {4} {5} {6}{7} -f ssegment -segment_list_flags +live -segment_time 10 -segment_list \"{8}\" \"{9}\"", + return string.Format("{0} {1} -i {2}{3} -threads 0 {4} {5} {6} -f ssegment -segment_list_flags +live -segment_time 10 -segment_list \"{7}\" \"{8}\"", probeSize, GetFastSeekCommandLineParameter(state.Request), GetInputArgument(state.Item, state.IsoMount), @@ -188,7 +186,6 @@ namespace MediaBrowser.Api.Playback.Hls GetMapArgs(state), GetVideoArguments(state), GetAudioArguments(state), - keyFrameArg, outputPath, segmentOutputPath ).Trim(); diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 4931383b6..04b84f791 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -115,7 +115,9 @@ namespace MediaBrowser.Api.Playback.Hls return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb" : "-codec:v:0 copy"; } - var args = "-codec:v:0 " + codec + " -preset superfast"; + const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+5))"; + + var args = "-codec:v:0 " + codec + " -preset superfast" + keyFrameArg; if (state.VideoRequest.VideoBitRate.HasValue) { diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index d6514bacb..45056d817 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -131,47 +131,47 @@ namespace MediaBrowser.Api.Playback.Progressive { var args = "-vcodec " + videoCodec; - var request = state.VideoRequest; - - // If we're encoding video, add additional params - if (!videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase)) + // See if we can save come cpu cycles by avoiding encoding + if (videoCodec.Equals("copy", StringComparison.OrdinalIgnoreCase)) { - // Add resolution params, if specified - if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue) - { - args += GetOutputSizeParam(state, videoCodec); - } + return IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb" : args; + } - if (request.Framerate.HasValue) - { - args += string.Format(" -r {0}", request.Framerate.Value); - } + const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,0),gte(t,prev_forced_t+2))"; - // Add the audio bitrate - var qualityParam = GetVideoQualityParam(request, videoCodec); + args += keyFrameArg; - if (!string.IsNullOrEmpty(qualityParam)) - { - args += " " + qualityParam; - } + var request = state.VideoRequest; + + // Add resolution params, if specified + if (request.Width.HasValue || request.Height.HasValue || request.MaxHeight.HasValue || request.MaxWidth.HasValue) + { + args += GetOutputSizeParam(state, videoCodec); + } - args += " -vsync vfr"; + if (request.Framerate.HasValue) + { + args += string.Format(" -r {0}", request.Framerate.Value); + } - if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) - { - args += " -profile:v " + state.VideoRequest.Profile; - } + // Add the audio bitrate + var qualityParam = GetVideoQualityParam(request, videoCodec); - if (!string.IsNullOrEmpty(state.VideoRequest.Level)) - { - args += " -level 3 " + state.VideoRequest.Level; - } + if (!string.IsNullOrEmpty(qualityParam)) + { + args += " " + qualityParam; + } + args += " -vsync vfr"; + + if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) + { + args += " -profile:v " + state.VideoRequest.Profile; } - else if (IsH264(state.VideoStream)) + + if (!string.IsNullOrEmpty(state.VideoRequest.Level)) { - // FFmpeg will fail to convert and give h264 bitstream malformated error if it isn't used when converting mp4 to transport stream. - args += " -bsf h264_mp4toannexb"; + args += " -level 3 " + state.VideoRequest.Level; } return args; |
