Fix video quality at low bitrates when reducing bit depth

10-bit encoded video offers higher efficiency. When reducing the bit depth,
compensation is required to maintain quality at low bitrates.

A recent change to the bitrate parsing logic exposed this issue, as it
prioritizes reading the video stream bitrate from MKV tags rather than
relying on the bitrate of the entire container.

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
This commit is contained in:
nyanmisaka committed 2026-10-03 14:40:08 +08:00
1 parent e431aadd92
commit bbc40674a8
1 file changed
+23
@@ -2693,6 +2693,28 @@ namespace MediaBrowser.Controller.MediaEncoding
return reasons;
}
private static int GetBitDepthCompensatedBitrate(int bitrate, MediaStream videoStream, int targetBitDepth)
{
if (targetBitDepth >= 10
|| (videoStream.BitDepth is int bitDepth && bitDepth <= targetBitDepth)
|| videoStream.BitRate is not int sourceBitrate)
{
return bitrate;
}
// Bit depth reduction requires bit rate compensation because
// 10-bit encoded video is significantly more efficient.
var factor = sourceBitrate switch
{
<= 4_000_000 => 1.5,
<= 8_000_000 => 1.2,
<= 12_000_000 => 1.1,
_ => 1.05
};
return Convert.ToInt32(bitrate * factor);
}
public int GetVideoBitrateParamValue(BaseEncodingJobOptions request, MediaStream videoStream, string outputVideoCodec)
{
var bitrate = request.VideoBitRate;
@@ -2715,6 +2737,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (bitrate.HasValue)
{
var inputVideoCodec = videoStream.Codec;
bitrate = GetBitDepthCompensatedBitrate(bitrate.Value, videoStream, 8);
bitrate = ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec);
// If a max bitrate was requested, don't let the scaled bitrate exceed it