From cf8aa37f5bd9bc76a78aac4e4232328f82fa4596 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Thu, 17 Dec 2020 23:33:44 +0800 Subject: [PATCH] Fix some video profile for Android client * Fix constrained high profile for some encoders * Extended profile is not supported by any known h264 encoders * Replace HEVC 10-bit profiles with main profile --- .../MediaEncoding/EncodingHelper.cs | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 91a03e647..a8a094e63 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -1130,10 +1130,22 @@ namespace MediaBrowser.Controller.MediaEncoding var profile = state.GetRequestedProfiles(targetVideoCodec).FirstOrDefault(); profile = Regex.Replace(profile, @"\s+", String.Empty); + // We only transcode to HEVC 8-bit for now, force Main Profile. + if (profile.Contains("main 10", StringComparison.OrdinalIgnoreCase) + || profile.Contains("main still", StringComparison.OrdinalIgnoreCase)) + { + profile = "main"; + } + + // Extended Profile is not supported by any known h264 encoders, force Main Profile. + if (profile.Contains("extended", StringComparison.OrdinalIgnoreCase)) + { + profile = "main"; + } + // Only libx264 support encoding H264 High 10 Profile, otherwise force High Profile. if (!string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase) - && profile != null - && profile.IndexOf("high 10", StringComparison.OrdinalIgnoreCase) != -1) + && profile.Contains("high 10", StringComparison.OrdinalIgnoreCase)) { profile = "high"; } @@ -1141,8 +1153,7 @@ namespace MediaBrowser.Controller.MediaEncoding // h264_vaapi does not support Baseline profile, force Constrained Baseline in this case, // which is compatible (and ugly). if (string.Equals(videoEncoder, "h264_vaapi", StringComparison.OrdinalIgnoreCase) - && profile != null - && profile.IndexOf("baseline", StringComparison.OrdinalIgnoreCase) != -1) + && profile.Contains("baseline", StringComparison.OrdinalIgnoreCase)) { profile = "constrained_baseline"; } @@ -1151,16 +1162,24 @@ namespace MediaBrowser.Controller.MediaEncoding if ((string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase) || string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) || string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) - && profile != null - && profile.IndexOf("baseline", StringComparison.OrdinalIgnoreCase) != -1) + && profile.Contains("baseline", StringComparison.OrdinalIgnoreCase)) { profile = "baseline"; } + // libx264, h264_qsv, h264_nvenc and h264_vaapi does not support Constrained High profile, force High in this case. + if ((string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase) + || string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) + || string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase) + || string.Equals(videoEncoder, "h264_vaapi", StringComparison.OrdinalIgnoreCase)) + && profile.Contains("high", StringComparison.OrdinalIgnoreCase)) + { + profile = "high"; + } + // Currently hevc_amf only support encoding HEVC Main Profile, otherwise force Main Profile. - if (!string.Equals(videoEncoder, "hevc_amf", StringComparison.OrdinalIgnoreCase) - && profile != null - && profile.IndexOf("main 10", StringComparison.OrdinalIgnoreCase) != -1) + if (string.Equals(videoEncoder, "hevc_amf", StringComparison.OrdinalIgnoreCase) + && profile.Contains("main 10", StringComparison.OrdinalIgnoreCase)) { profile = "main"; }