aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-06-28 17:34:20 +0200
committerGitHub <noreply@github.com>2023-06-28 17:34:20 +0200
commite53e53eb29cca3b316fcf8f57abfa1c0f2807d99 (patch)
treec291fed6cf96a80fc30c1112ffc229cbc475b0a5 /Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
parent4ac07f6c76bf8eed3b99994410dd1481764ab9fc (diff)
parentdf880ff785287714e9517ee70ed4a114b867ff0a (diff)
Merge pull request #9907 from nyanmisaka/av1e
Diffstat (limited to 'Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs')
-rw-r--r--Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
index 995488397..9a141a16d 100644
--- a/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
+++ b/Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
@@ -179,4 +179,62 @@ public static class HlsCodecStringHelpers
return result.ToString();
}
+
+ /// <summary>
+ /// Gets an AV1 codec string.
+ /// </summary>
+ /// <param name="profile">AV1 profile.</param>
+ /// <param name="level">AV1 level.</param>
+ /// <param name="tierFlag">AV1 tier flag.</param>
+ /// <param name="bitDepth">AV1 bit depth.</param>
+ /// <returns>The AV1 codec string.</returns>
+ 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('.')
+ .Append(level)
+ .Append(tierFlag ? 'H' : 'M');
+
+ string bitDepthD2 = bitDepth.ToString("D2", CultureInfo.InvariantCulture);
+ result.Append('.')
+ .Append(bitDepthD2);
+
+ return result.ToString();
+ }
}