Jelajahi Sumber

increase unification of param building

Luke Pulverenti 8 tahun lalu
induk
melakukan
59ac045c6b

+ 4 - 2
MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs

@@ -109,11 +109,13 @@ namespace MediaBrowser.Api.Playback.Hls
         public Task<object> Get(GetHlsVideoSegmentLegacy request)
         {
             var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
-            file = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, file);
+
+            var transcodeFolderPath = _config.ApplicationPaths.TranscodingTempPath;
+            file = Path.Combine(transcodeFolderPath, file);
 
             var normalizedPlaylistId = request.PlaylistId;
 
-            var playlistPath = _fileSystem.GetFilePaths(_config.ApplicationPaths.TranscodingTempPath)
+            var playlistPath = _fileSystem.GetFilePaths(transcodeFolderPath)
                 .FirstOrDefault(i => string.Equals(Path.GetExtension(i), ".m3u8", StringComparison.OrdinalIgnoreCase) && i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1);
 
             return GetFileResult(file, playlistPath);

+ 0 - 3
MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs

@@ -15,9 +15,6 @@ using System.Globalization;
 using System.IO;
 using System.Threading;
 using System.Threading.Tasks;
-using MediaBrowser.Common.IO;
-using MediaBrowser.Controller.IO;
-using MediaBrowser.Model.IO;
 using MediaBrowser.Model.Services;
 
 namespace MediaBrowser.Api.Playback.Progressive

+ 2 - 72
MediaBrowser.Api/Playback/Progressive/VideoService.cs

@@ -1,4 +1,3 @@
-using MediaBrowser.Common.Net;
 using MediaBrowser.Controller.Configuration;
 using MediaBrowser.Controller.Devices;
 using MediaBrowser.Controller.Dlna;
@@ -9,12 +8,8 @@ using MediaBrowser.Model.IO;
 using MediaBrowser.Model.Serialization;
 using System;
 using System.IO;
-using System.Linq;
 using System.Threading.Tasks;
-using MediaBrowser.Common.IO;
-using MediaBrowser.Controller.IO;
 using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.IO;
 using MediaBrowser.Model.Dlna;
 using MediaBrowser.Model.Services;
 
@@ -116,11 +111,6 @@ namespace MediaBrowser.Api.Playback.Progressive
 
             var inputModifier = EncodingHelper.GetInputModifier(state, encodingOptions);
 
-            var subtitleArguments = state.SubtitleStream != null &&
-                                    state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Embed
-                ? GetSubtitleArguments(state)
-                : string.Empty;
-
             return string.Format("{0} {1}{2} {3} {4} -map_metadata -1 -map_chapters -1 -threads {5} {6}{7}{8} -y \"{9}\"",
                 inputModifier,
                 EncodingHelper.GetInputArgument(state, encodingOptions),
@@ -128,30 +118,13 @@ namespace MediaBrowser.Api.Playback.Progressive
                 EncodingHelper.GetMapArgs(state),
                 GetVideoArguments(state, videoCodec),
                 threads,
-                GetAudioArguments(state),
-                subtitleArguments,
+                EncodingHelper.GetProgressiveVideoAudioArguments(state, encodingOptions),
+                EncodingHelper.GetSubtitleEmbedArguments(state),
                 format,
                 outputPath
                 ).Trim();
         }
 
-        private string GetSubtitleArguments(StreamState state)
-        {
-            var format = state.SupportedSubtitleCodecs.FirstOrDefault();
-            string codec;
-
-            if (string.IsNullOrWhiteSpace(format) || string.Equals(format, state.SubtitleStream.Codec, StringComparison.OrdinalIgnoreCase))
-            {
-                codec = "copy";
-            }
-            else
-            {
-                codec = format;
-            }
-
-            return " -codec:s:0 " + codec;
-        }
-
         /// <summary>
         /// Gets video arguments to pass to ffmpeg
         /// </summary>
@@ -233,48 +206,5 @@ namespace MediaBrowser.Api.Playback.Progressive
 
             return args;
         }
-
-        /// <summary>
-        /// Gets audio arguments to pass to ffmpeg
-        /// </summary>
-        /// <param name="state">The state.</param>
-        /// <returns>System.String.</returns>
-        private string GetAudioArguments(StreamState state)
-        {
-            // If the video doesn't have an audio stream, return a default.
-            if (state.AudioStream == null && state.VideoStream != null)
-            {
-                return string.Empty;
-            }
-
-            // Get the output codec name
-            var codec = EncodingHelper.GetAudioEncoder(state);
-
-            var args = "-codec:a:0 " + codec;
-
-            if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
-            {
-                return args;
-            }
-
-            // Add the number of audio channels
-            var channels = state.OutputAudioChannels;
-
-            if (channels.HasValue)
-            {
-                args += " -ac " + channels.Value;
-            }
-
-            var bitrate = state.OutputAudioBitrate;
-
-            if (bitrate.HasValue)
-            {
-                args += " -ab " + bitrate.Value.ToString(UsCulture);
-            }
-
-            args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), false);
-
-            return args;
-        }
     }
 }

+ 0 - 2
MediaBrowser.Api/Playback/StreamRequest.cs

@@ -32,8 +32,6 @@ namespace MediaBrowser.Api.Playback
         [ApiMember(Name = "AudioCodec", Description = "Optional. Specify a audio codec to encode to, e.g. mp3. If omitted the server will auto-select using the url's extension. Options: aac, mp3, vorbis, wma.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string AudioCodec { get; set; }
 
-        public string SubtitleCodec { get; set; }
-
         [ApiMember(Name = "DeviceProfileId", Description = "Optional. The dlna device profile id to utilize.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string DeviceProfileId { get; set; }
 

+ 0 - 3
MediaBrowser.Api/Playback/StreamState.cs

@@ -120,7 +120,6 @@ namespace MediaBrowser.Api.Playback
             }
         }
 
-        public List<string> SupportedSubtitleCodecs { get; set; }
         public string UserAgent { get; set; }
         public TranscodingJobType TranscodingType { get; set; }
 
@@ -129,7 +128,6 @@ namespace MediaBrowser.Api.Playback
         {
             _mediaSourceManager = mediaSourceManager;
             _logger = logger;
-            SupportedSubtitleCodecs = new List<string>();
             TranscodingType = transcodingType;
         }
 
@@ -209,7 +207,6 @@ namespace MediaBrowser.Api.Playback
         }
 
         public string OutputFilePath { get; set; }
-        public int? OutputAudioBitrate;
 
         public string ActualOutputVideoCodec
         {

+ 74 - 0
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

@@ -1736,5 +1736,79 @@ namespace MediaBrowser.Controller.MediaEncoding
 
             return threads;
         }
+
+        public string GetSubtitleEmbedArguments(EncodingJobInfo state)
+        {
+            if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)
+            {
+                return string.Empty;
+            }
+
+            var format = state.SupportedSubtitleCodecs.FirstOrDefault();
+            string codec;
+
+            if (string.IsNullOrWhiteSpace(format) || string.Equals(format, state.SubtitleStream.Codec, StringComparison.OrdinalIgnoreCase))
+            {
+                codec = "copy";
+            }
+            else
+            {
+                codec = format;
+            }
+
+            // Muxing in dvbsub via either copy or -codec dvbsub does not seem to work
+            // It doesn't throw any errors but vlc on android will not render them
+            // They will need to be converted to an alternative format
+            // TODO: This is incorrectly assuming that dvdsub will be supported by the player
+            // The api will need to be expanded to accomodate this.
+            if (string.Equals(state.SubtitleStream.Codec, "DVBSUB", StringComparison.OrdinalIgnoreCase))
+            {
+                codec = "dvdsub";
+            }
+
+            var args = " -codec:s:0 " + codec;
+
+            args += " -disposition:s:0 default";
+
+            return args;
+        }
+
+        public string GetProgressiveVideoAudioArguments(EncodingJobInfo state, EncodingOptions encodingOptions)
+        {
+            // If the video doesn't have an audio stream, return a default.
+            if (state.AudioStream == null && state.VideoStream != null)
+            {
+                return string.Empty;
+            }
+
+            // Get the output codec name
+            var codec = GetAudioEncoder(state);
+
+            var args = "-codec:a:0 " + codec;
+
+            if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
+            {
+                return args;
+            }
+
+            // Add the number of audio channels
+            var channels = state.OutputAudioChannels;
+
+            if (channels.HasValue)
+            {
+                args += " -ac " + channels.Value;
+            }
+
+            var bitrate = state.OutputAudioBitrate;
+
+            if (bitrate.HasValue)
+            {
+                args += " -ab " + bitrate.Value.ToString(_usCulture);
+            }
+            
+            args += " " + GetAudioFilterParam(state, encodingOptions, false);
+
+            return args;
+        }
     }
 }

+ 4 - 1
MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs

@@ -29,6 +29,7 @@ namespace MediaBrowser.Controller.MediaEncoding
         public int? OutputVideoBitrate { get; set; }
         public MediaStream SubtitleStream { get; set; }
         public SubtitleDeliveryMethod SubtitleDeliveryMethod { get; set; }
+        public List<string> SupportedSubtitleCodecs { get; set; }
 
         public int InternalSubtitleStreamOffset { get; set; }
         public MediaSourceInfo MediaSource { get; set; }
@@ -64,6 +65,7 @@ namespace MediaBrowser.Controller.MediaEncoding
             get { return BaseRequest.CopyTimestamps; }
         }
 
+        public int? OutputAudioBitrate;
         public int? OutputAudioChannels;
         public int? OutputAudioSampleRate;
         public bool DeInterlace { get; set; }
@@ -74,8 +76,9 @@ namespace MediaBrowser.Controller.MediaEncoding
             _logger = logger;
             RemoteHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
             PlayableStreamFileNames = new List<string>();
+            SupportedAudioCodecs = new List<string>();
             SupportedVideoCodecs = new List<string>();
-            SupportedVideoCodecs = new List<string>();
+            SupportedSubtitleCodecs = new List<string>();
         }
 
         /// <summary>

+ 2 - 0
MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs

@@ -198,6 +198,8 @@ namespace MediaBrowser.Controller.MediaEncoding
         [ApiMember(Name = "VideoCodec", Description = "Optional. Specify a video codec to encode to, e.g. h264. If omitted the server will auto-select using the url's extension. Options: h264, mpeg4, theora, vpx, wmv.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string VideoCodec { get; set; }
 
+        public string SubtitleCodec { get; set; }
+
         /// <summary>
         /// Gets or sets the index of the audio stream.
         /// </summary>

+ 1 - 1
MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs

@@ -66,7 +66,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
             IProgress<double> progress,
             CancellationToken cancellationToken)
         {
-            var encodingJob = await new EncodingJobFactory(Logger, LibraryManager, MediaSourceManager, ConfigurationManager)
+            var encodingJob = await new EncodingJobFactory(Logger, LibraryManager, MediaSourceManager, ConfigurationManager, MediaEncoder)
                 .CreateJob(options, EncodingHelper, IsVideoEncoder, progress, cancellationToken).ConfigureAwait(false);
 
             encodingJob.OutputFilePath = GetOutputFilePath(encodingJob);

+ 0 - 1
MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs

@@ -109,7 +109,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
         }
 
         public string OutputFilePath { get; set; }
-        public int? OutputAudioBitrate;
 
         public string ActualOutputVideoCodec
         {

+ 10 - 1
MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs

@@ -22,15 +22,17 @@ namespace MediaBrowser.MediaEncoding.Encoder
         private readonly ILibraryManager _libraryManager;
         private readonly IMediaSourceManager _mediaSourceManager;
         private readonly IConfigurationManager _config;
+        private readonly IMediaEncoder _mediaEncoder;
 
         protected static readonly CultureInfo UsCulture = new CultureInfo("en-US");
         
-        public EncodingJobFactory(ILogger logger, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager, IConfigurationManager config)
+        public EncodingJobFactory(ILogger logger, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager, IConfigurationManager config, IMediaEncoder mediaEncoder)
         {
             _logger = logger;
             _libraryManager = libraryManager;
             _mediaSourceManager = mediaSourceManager;
             _config = config;
+            _mediaEncoder = mediaEncoder;
         }
 
         public async Task<EncodingJob> CreateJob(EncodingJobOptions options, EncodingHelper encodingHelper, bool isVideoRequest, IProgress<double> progress, CancellationToken cancellationToken)
@@ -61,6 +63,13 @@ namespace MediaBrowser.MediaEncoding.Encoder
                 request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault();
             }
 
+            if (!string.IsNullOrWhiteSpace(request.SubtitleCodec))
+            {
+                state.SupportedSubtitleCodecs = request.SubtitleCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToList();
+                request.SubtitleCodec = state.SupportedSubtitleCodecs.FirstOrDefault(i => _mediaEncoder.CanEncodeToSubtitleCodec(i))
+                    ?? state.SupportedSubtitleCodecs.FirstOrDefault();
+            }
+
             var item = _libraryManager.GetItemById(request.ItemId);
             state.ItemType = item.GetType().Name;
 

+ 1 - 44
MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs

@@ -47,7 +47,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
                 EncodingHelper.GetMapArgs(state),
                 videoArguments,
                 threads,
-                GetAudioArguments(state),
+                EncodingHelper.GetProgressiveVideoAudioArguments(state, encodingOptions),
                 format,
                 state.OutputFilePath
                 ).Trim();
@@ -114,49 +114,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
             return args;
         }
 
-        /// <summary>
-        /// Gets audio arguments to pass to ffmpeg
-        /// </summary>
-        /// <param name="state">The state.</param>
-        /// <returns>System.String.</returns>
-        private string GetAudioArguments(EncodingJob state)
-        {
-            // If the video doesn't have an audio stream, return a default.
-            if (state.AudioStream == null && state.VideoStream != null)
-            {
-                return string.Empty;
-            }
-
-            // Get the output codec name
-            var codec = EncodingHelper.GetAudioEncoder(state);
-
-            var args = "-codec:a:0 " + codec;
-
-            if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
-            {
-                return args;
-            }
-
-            // Add the number of audio channels
-            var channels = state.OutputAudioChannels;
-
-            if (channels.HasValue)
-            {
-                args += " -ac " + channels.Value;
-            }
-
-            var bitrate = state.OutputAudioBitrate;
-
-            if (bitrate.HasValue)
-            {
-                args += " -ab " + bitrate.Value.ToString(UsCulture);
-            }
-
-            args += " " + EncodingHelper.GetAudioFilterParam(state, GetEncodingOptions(), false);
-
-            return args;
-        }
-
         protected override string GetOutputFileExtension(EncodingJob state)
         {
             var ext = base.GetOutputFileExtension(state);