Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remuxing support for VP9 #11489

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Jellyfin.Api/Helpers/DynamicHlsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,21 @@ private string GetPlaylistVideoCodecs(StreamState state, string codec, int level
return HlsCodecStringHelpers.GetAv1String(profile, level, false, bitDepth);
}

// VP9 HLS is for video remuxing only, everything is probed from the original video
if (string.Equals(codec, "vp9", StringComparison.OrdinalIgnoreCase))
{
var width = state.VideoStream.Width ?? 0;
var height = state.VideoStream.Height ?? 0;
var framerate = state.VideoStream.AverageFrameRate ?? 30;
var bitDepth = state.VideoStream.BitDepth ?? 8;
return HlsCodecStringHelpers.GetVp9String(
width,
height,
state.VideoStream.PixelFormat,
framerate,
bitDepth);
}

return string.Empty;
}

Expand Down
62 changes: 62 additions & 0 deletions Jellyfin.Api/Helpers/HlsCodecStringHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,68 @@ public static string GetH265String(string? profile, int level)
return result.ToString();
}

/// <summary>
/// Gets a VP9 codec string.
/// </summary>
/// <param name="width">Video width.</param>
/// <param name="height">Video height.</param>
/// <param name="pixelFormat">Video pixel format.</param>
/// <param name="framerate">Video framerate.</param>
/// <param name="bitDepth">Video bitDepth.</param>
/// <returns>The VP9 codec string.</returns>
public static string GetVp9String(int width, int height, string pixelFormat, float framerate, int bitDepth)
{
// refer: https://www.webmproject.org/vp9/mp4/
StringBuilder result = new StringBuilder("vp09", 13);

var profileString = pixelFormat switch
{
"yuv420p" => "00",
"yuvj420p" => "00",
"yuv422p" => "01",
"yuv444p" => "01",
"yuv420p10le" => "02",
"yuv420p12le" => "02",
"yuv422p10le" => "03",
"yuv422p12le" => "03",
"yuv444p10le" => "03",
"yuv444p12le" => "03",
_ => "00"
};

var lumaPictureSize = width * height;
var lumaSampleRate = lumaPictureSize * framerate;
var levelString = lumaPictureSize switch
{
<= 0 => "00",
<= 36864 => "10",
<= 73728 => "11",
<= 122880 => "20",
<= 245760 => "21",
<= 552960 => "30",
<= 983040 => "31",
<= 2228224 => lumaSampleRate <= 83558400 ? "40" : "41",
<= 8912896 => lumaSampleRate <= 311951360 ? "50" : (lumaSampleRate <= 588251136 ? "51" : "52"),
<= 35651584 => lumaSampleRate <= 1176502272 ? "60" : (lumaSampleRate <= 4706009088 ? "61" : "62"),
_ => "00" // This should not happen
};

if (bitDepth != 8
&& bitDepth != 10
&& bitDepth != 12)
{
// Default to 8 bits
bitDepth = 8;
}

result.Append('.').Append(profileString).Append('.').Append(levelString);
var bitDepthD2 = bitDepth.ToString("D2", CultureInfo.InvariantCulture);
result.Append('.')
.Append(bitDepthD2);

return result.ToString();
}

/// <summary>
/// Gets an AV1 codec string.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Model/Dlna/StreamBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class StreamBuilder

private readonly ILogger _logger;
private readonly ITranscoderSupport _transcoderSupport;
private static readonly string[] _supportedHlsVideoCodecs = new string[] { "h264", "hevc", "av1" };
private static readonly string[] _supportedHlsVideoCodecs = new string[] { "h264", "hevc", "vp9", "av1" };
private static readonly string[] _supportedHlsAudioCodecsTs = new string[] { "aac", "ac3", "eac3", "mp3" };
private static readonly string[] _supportedHlsAudioCodecsMp4 = new string[] { "aac", "ac3", "eac3", "mp3", "alac", "flac", "opus", "dca", "truehd" };

Expand Down