From 0df6fd9cf28ddec98e0418ca08e8b42046ff677f Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Mon, 19 Jun 2023 22:50:09 +0800 Subject: Add AV1 support in HLS streaming Signed-off-by: nyanmisaka --- Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs') diff --git a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs index 995488397..ad1fce0f1 100644 --- a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs +++ b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs @@ -179,4 +179,60 @@ public static class HlsCodecStringHelpers return result.ToString(); } + + /// + /// Gets a AV1 codec string. + /// + /// AV1 profile. + /// AV1 level. + /// AV1 tier flag. + /// AV1 bit depth. + /// AV1 string. + public static string GetAv1String(string? profile, int level, bool tierFlag, int bitDepth) + { + // https://aomedia.org/av1/specification/annex-a/ + // FORMAT: [codecTag].[profile].[level][tier].[bitDepth] + StringBuilder result = new StringBuilder("av01", 13); + + if (string.Equals(profile, "Main", StringComparison.OrdinalIgnoreCase)) + { + result.Append(".0"); + } + else if (string.Equals(profile, "High", StringComparison.OrdinalIgnoreCase)) + { + result.Append(".1"); + } + else if (string.Equals(profile, "Professional", StringComparison.OrdinalIgnoreCase)) + { + result.Append(".2"); + } + else + { + // Default to Main + result.Append(".0"); + } + + if (level <= 0 + || level > 31) + { + // Default to the maximum defined level 6.3 + level = 19; + } + + if (bitDepth != 8 + && bitDepth != 10 + && bitDepth != 12) + { + // Default to 8 bits + bitDepth = 8; + } + + result.Append("." + level) + .Append(tierFlag ? "H" : "M"); + + string bitDepthD2 = bitDepth.ToString("D2", CultureInfo.InvariantCulture); + result.Append("." + bitDepthD2); + + return result.ToString(); + } } -- cgit v1.2.3