diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 8d01e4021f..c300fcce3e 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Diagnostics; namespace MediaBrowser.Api.Playback @@ -100,11 +101,7 @@ namespace MediaBrowser.Api.Playback /// /// Gets the command line arguments. /// - /// The output path. - /// The state. - /// if set to true [is encoding]. - /// System.String. - protected abstract string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding); + protected abstract string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding); /// /// Gets the type of the transcoding job. @@ -125,11 +122,11 @@ namespace MediaBrowser.Api.Playback /// /// Gets the output file path. /// - private string GetOutputFilePath(StreamState state, string outputFileExtension) + private string GetOutputFilePath(StreamState state, EncodingOptions encodingOptions, string outputFileExtension) { var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; - var data = GetCommandLineArguments("dummy\\dummy", state, false); + var data = GetCommandLineArguments("dummy\\dummy", encodingOptions, state, false); data += "-" + (state.Request.DeviceId ?? string.Empty); data += "-" + (state.Request.PlaySessionId ?? string.Empty); @@ -217,8 +214,10 @@ namespace MediaBrowser.Api.Playback } } + var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); + var transcodingId = Guid.NewGuid().ToString("N"); - var commandLineArgs = GetCommandLineArguments(outputPath, state, true); + var commandLineArgs = GetCommandLineArguments(outputPath, encodingOptions, state, true); var process = ApiEntryPoint.Instance.ProcessFactory.Create(new ProcessOptions { @@ -826,7 +825,10 @@ namespace MediaBrowser.Api.Playback var ext = string.IsNullOrWhiteSpace(state.OutputContainer) ? GetOutputFileExtension(state) : ("." + state.OutputContainer); - state.OutputFilePath = GetOutputFilePath(state, ext); + + var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); + + state.OutputFilePath = GetOutputFilePath(state, encodingOptions, ext); return state; } diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 63d2cd9ebe..83157c7031 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -14,6 +14,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Configuration; namespace MediaBrowser.Api.Playback.Hls { @@ -25,15 +26,12 @@ namespace MediaBrowser.Api.Playback.Hls /// /// Gets the audio arguments. /// - /// The state. - /// System.String. - protected abstract string GetAudioArguments(StreamState state); + protected abstract string GetAudioArguments(StreamState state, EncodingOptions encodingOptions); + /// /// Gets the video arguments. /// - /// The state. - /// System.String. - protected abstract string GetVideoArguments(StreamState state); + protected abstract string GetVideoArguments(StreamState state, EncodingOptions encodingOptions); /// /// Gets the segment file extension. @@ -242,10 +240,8 @@ namespace MediaBrowser.Api.Playback.Hls } } - protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) + protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding) { - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); - var itsOffsetMs = 0; var itsOffset = itsOffsetMs == 0 ? string.Empty : string.Format("-itsoffset {0} ", TimeSpan.FromMilliseconds(itsOffsetMs).TotalSeconds.ToString(UsCulture)); @@ -285,8 +281,8 @@ namespace MediaBrowser.Api.Playback.Hls EncodingHelper.GetInputArgument(state, encodingOptions), threads, EncodingHelper.GetMapArgs(state), - GetVideoArguments(state), - GetAudioArguments(state), + GetVideoArguments(state, encodingOptions), + GetAudioArguments(state, encodingOptions), state.SegmentLength.ToString(UsCulture), startNumberParam, outputPath, @@ -306,8 +302,8 @@ namespace MediaBrowser.Api.Playback.Hls EncodingHelper.GetInputArgument(state, encodingOptions), threads, EncodingHelper.GetMapArgs(state), - GetVideoArguments(state), - GetAudioArguments(state), + GetVideoArguments(state, encodingOptions), + GetAudioArguments(state, encodingOptions), state.SegmentLength.ToString(UsCulture), startNumberParam, state.HlsListSize.ToString(UsCulture), diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 2fc8fccbee..6744fbd92c 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -18,6 +18,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Services; using MimeTypes = MediaBrowser.Model.Net.MimeTypes; @@ -777,7 +778,7 @@ namespace MediaBrowser.Api.Playback.Hls return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } - protected override string GetAudioArguments(StreamState state) + protected override string GetAudioArguments(StreamState state, EncodingOptions encodingOptions) { var audioCodec = EncodingHelper.GetAudioEncoder(state); @@ -813,7 +814,7 @@ namespace MediaBrowser.Api.Playback.Hls if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase)) { - var videoCodec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions()); + var videoCodec = EncodingHelper.GetVideoEncoder(state, encodingOptions); if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.EnableBreakOnNonKeyFrames(videoCodec)) { @@ -844,19 +845,19 @@ namespace MediaBrowser.Api.Playback.Hls args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture); } - args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true); + args += " " + EncodingHelper.GetAudioFilterParam(state, encodingOptions, true); return args; } - protected override string GetVideoArguments(StreamState state) + protected override string GetVideoArguments(StreamState state, EncodingOptions encodingOptions) { if (!state.IsOutputVideo) { return string.Empty; } - var codec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions()); + var codec = EncodingHelper.GetVideoEncoder(state, encodingOptions); var args = "-codec:v:0 " + codec; @@ -882,8 +883,6 @@ namespace MediaBrowser.Api.Playback.Hls var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode; - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); - args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg; //args += " -mixed-refs 0 -refs 3 -x264opts b_pyramid=0:weightb=0:weightp=0"; @@ -918,9 +917,8 @@ namespace MediaBrowser.Api.Playback.Hls return args; } - protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) + protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding) { - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); var threads = EncodingHelper.GetNumberOfThreads(state, encodingOptions, false); var inputModifier = EncodingHelper.GetInputModifier(state, encodingOptions); @@ -947,7 +945,7 @@ namespace MediaBrowser.Api.Playback.Hls segmentFormat = "mpegts"; } - var videoCodec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions()); + var videoCodec = EncodingHelper.GetVideoEncoder(state, encodingOptions); var breakOnNonKeyFrames = state.EnableBreakOnNonKeyFrames(videoCodec); var breakOnNonKeyFramesArg = breakOnNonKeyFrames ? " -break_non_keyframes 1" : ""; @@ -957,8 +955,8 @@ namespace MediaBrowser.Api.Playback.Hls EncodingHelper.GetInputArgument(state, encodingOptions), threads, mapArgs, - GetVideoArguments(state), - GetAudioArguments(state), + GetVideoArguments(state, encodingOptions), + GetAudioArguments(state, encodingOptions), state.SegmentLength.ToString(UsCulture), startNumberParam, outputPath, diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 227b55b1bc..9b3c8a08f1 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -7,6 +7,7 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; using System; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Services; @@ -31,9 +32,7 @@ namespace MediaBrowser.Api.Playback.Hls /// /// Gets the audio arguments. /// - /// The state. - /// System.String. - protected override string GetAudioArguments(StreamState state) + protected override string GetAudioArguments(StreamState state, EncodingOptions encodingOptions) { var codec = EncodingHelper.GetAudioEncoder(state); @@ -63,7 +62,7 @@ namespace MediaBrowser.Api.Playback.Hls args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture); } - args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true); + args += " " + EncodingHelper.GetAudioFilterParam(state, encodingOptions, true); return args; } @@ -71,16 +70,14 @@ namespace MediaBrowser.Api.Playback.Hls /// /// Gets the video arguments. /// - /// The state. - /// System.String. - protected override string GetVideoArguments(StreamState state) + protected override string GetVideoArguments(StreamState state, EncodingOptions encodingOptions) { if (!state.IsOutputVideo) { return string.Empty; } - var codec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions()); + var codec = EncodingHelper.GetVideoEncoder(state, encodingOptions); var args = "-codec:v:0 " + codec; @@ -106,7 +103,6 @@ namespace MediaBrowser.Api.Playback.Hls var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode; - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg; // Add resolution params, if specified diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs index af8670eb15..44e096dd7f 100644 --- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs +++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs @@ -10,6 +10,7 @@ using MediaBrowser.Model.Serialization; using System.Collections.Generic; using System.Threading.Tasks; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.IO; using MediaBrowser.Model.Services; using MediaBrowser.Model.System; @@ -58,10 +59,8 @@ namespace MediaBrowser.Api.Playback.Progressive return ProcessRequest(request, true); } - protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) + protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding) { - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); - return EncodingHelper.GetProgressiveAudioFullCommandLine(state, encodingOptions, outputPath); } } diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 5e21f6a841..a41b4cbf54 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -8,6 +8,7 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; using System.Threading.Tasks; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Services; using MediaBrowser.Model.System; @@ -91,10 +92,8 @@ namespace MediaBrowser.Api.Playback.Progressive return ProcessRequest(request, true); } - protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) + protected override string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding) { - var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions(); - return EncodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, outputPath, GetDefaultH264Preset()); } }