소스 검색

add an option to disable hevc encoding

nyanmisaka 4 년 전
부모
커밋
5bd0c2b69d

+ 3 - 1
Jellyfin.Api/Helpers/StreamingHelpers.cs

@@ -165,7 +165,9 @@ namespace Jellyfin.Api.Helpers
                 state.DirectStreamProvider = liveStreamInfo.Item2;
                 state.DirectStreamProvider = liveStreamInfo.Item2;
             }
             }
 
 
-            encodingHelper.AttachMediaSourceInfo(state, mediaSource, url);
+            var encodingOptions = serverConfigurationManager.GetEncodingOptions();
+
+            encodingHelper.AttachMediaSourceInfo(state, encodingOptions, mediaSource, url);
 
 
             string? containerInternal = Path.GetExtension(state.RequestedUrl);
             string? containerInternal = Path.GetExtension(state.RequestedUrl);
 
 

+ 2 - 1
Jellyfin.Api/Helpers/TranscodingJobHelper.cs

@@ -770,8 +770,9 @@ namespace Jellyfin.Api.Helpers
                     new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken },
                     new LiveStreamRequest { OpenToken = state.MediaSource.OpenToken },
                     cancellationTokenSource.Token)
                     cancellationTokenSource.Token)
                     .ConfigureAwait(false);
                     .ConfigureAwait(false);
+                var encodingOptions = _serverConfigurationManager.GetEncodingOptions();
 
 
-                _encodingHelper.AttachMediaSourceInfo(state, liveStreamResponse.MediaSource, state.RequestedUrl);
+                _encodingHelper.AttachMediaSourceInfo(state, encodingOptions, liveStreamResponse.MediaSource, state.RequestedUrl);
 
 
                 if (state.VideoRequest != null)
                 if (state.VideoRequest != null)
                 {
                 {

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

@@ -2631,6 +2631,7 @@ namespace MediaBrowser.Controller.MediaEncoding
 
 
         public void AttachMediaSourceInfo(
         public void AttachMediaSourceInfo(
             EncodingJobInfo state,
             EncodingJobInfo state,
+            EncodingOptions encodingOptions,
             MediaSourceInfo mediaSource,
             MediaSourceInfo mediaSource,
             string requestedUrl)
             string requestedUrl)
         {
         {
@@ -2761,11 +2762,23 @@ namespace MediaBrowser.Controller.MediaEncoding
                 request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => _mediaEncoder.CanEncodeToAudioCodec(i))
                 request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => _mediaEncoder.CanEncodeToAudioCodec(i))
                     ?? state.SupportedAudioCodecs.FirstOrDefault();
                     ?? state.SupportedAudioCodecs.FirstOrDefault();
             }
             }
+
+            var supportedVideoCodecs = state.SupportedVideoCodecs;
+            if (request != null && supportedVideoCodecs != null && supportedVideoCodecs.Length > 0)
+            {
+                var supportedVideoCodecsList = supportedVideoCodecs.ToList();
+
+                ShiftVideoCodecsIfNeeded(supportedVideoCodecsList, encodingOptions);
+
+                state.SupportedVideoCodecs = supportedVideoCodecsList.ToArray();
+
+                request.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault();
+            }
         }
         }
 
 
         private void ShiftAudioCodecsIfNeeded(List<string> audioCodecs, MediaStream audioStream)
         private void ShiftAudioCodecsIfNeeded(List<string> audioCodecs, MediaStream audioStream)
         {
         {
-            // Nothing to do here
+            // No need to shift if there is only one supported audio codec.
             if (audioCodecs.Count < 2)
             if (audioCodecs.Count < 2)
             {
             {
                 return;
                 return;
@@ -2793,6 +2806,34 @@ namespace MediaBrowser.Controller.MediaEncoding
             }
             }
         }
         }
 
 
+        private void ShiftVideoCodecsIfNeeded(List<string> videoCodecs, EncodingOptions encodingOptions)
+        {
+            // Shift hevc/h265 to the end of list if hevc encoding is not allowed.
+            if (encodingOptions.AllowHevcEncoding)
+            {
+                return;
+            }
+
+            // No need to shift if there is only one supported video codec.
+            if (videoCodecs.Count < 2)
+            {
+                return;
+            }
+
+            var shiftVideoCodecs = new[] { "hevc", "h265" };
+            if (videoCodecs.All(i => shiftVideoCodecs.Contains(i, StringComparer.OrdinalIgnoreCase)))
+            {
+                return;
+            }
+
+            while (shiftVideoCodecs.Contains(videoCodecs[0], StringComparer.OrdinalIgnoreCase))
+            {
+                var removed = shiftVideoCodecs[0];
+                videoCodecs.RemoveAt(0);
+                videoCodecs.Add(removed);
+            }
+        }
+
         private void NormalizeSubtitleEmbed(EncodingJobInfo state)
         private void NormalizeSubtitleEmbed(EncodingJobInfo state)
         {
         {
             if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)
             if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)

+ 3 - 0
MediaBrowser.Model/Configuration/EncodingOptions.cs

@@ -63,6 +63,8 @@ namespace MediaBrowser.Model.Configuration
 
 
         public bool EnableHardwareEncoding { get; set; }
         public bool EnableHardwareEncoding { get; set; }
 
 
+        public bool AllowHevcEncoding { get; set; }
+
         public bool EnableSubtitleExtraction { get; set; }
         public bool EnableSubtitleExtraction { get; set; }
 
 
         public string[] HardwareDecodingCodecs { get; set; }
         public string[] HardwareDecodingCodecs { get; set; }
@@ -94,6 +96,7 @@ namespace MediaBrowser.Model.Configuration
             EnableDecodingColorDepth10Hevc = true;
             EnableDecodingColorDepth10Hevc = true;
             EnableDecodingColorDepth10Vp9 = true;
             EnableDecodingColorDepth10Vp9 = true;
             EnableHardwareEncoding = true;
             EnableHardwareEncoding = true;
+            AllowHevcEncoding = true;
             EnableSubtitleExtraction = true;
             EnableSubtitleExtraction = true;
             HardwareDecodingCodecs = new string[] { "h264", "vc1" };
             HardwareDecodingCodecs = new string[] { "h264", "vc1" };
         }
         }