From 020dad88678c8feb0f849a7798659c1184555d48 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 17 Sep 2024 17:01:42 +0800 Subject: [PATCH] Increase reference bitrate for high efficiency codecs --- src/components/playback/playersettingsmenu.js | 7 +++---- src/components/qualityOptions.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/playback/playersettingsmenu.js b/src/components/playback/playersettingsmenu.js index 543158b424..8cd2c52ec4 100644 --- a/src/components/playback/playersettingsmenu.js +++ b/src/components/playback/playersettingsmenu.js @@ -8,15 +8,14 @@ function showQualityMenu(player, btn) { const videoStream = playbackManager.currentMediaSource(player).MediaStreams.filter(function (stream) { return stream.Type === 'Video'; })[0]; - const videoWidth = videoStream ? videoStream.Width : null; - const videoHeight = videoStream ? videoStream.Height : null; + + const videoCodec = videoStream ? videoStream.Codec : null; const videoBitRate = videoStream ? videoStream.BitRate : null; const options = qualityoptions.getVideoQualityOptions({ currentMaxBitrate: playbackManager.getMaxStreamingBitrate(player), isAutomaticBitrateEnabled: playbackManager.enableAutomaticBitrateDetection(player), - videoWidth: videoWidth, - videoHeight: videoHeight, + videoCodec, videoBitRate, enableAuto: true }); diff --git a/src/components/qualityOptions.js b/src/components/qualityOptions.js index cffd738525..4520c50847 100644 --- a/src/components/qualityOptions.js +++ b/src/components/qualityOptions.js @@ -3,6 +3,8 @@ import globalize from '../lib/globalize'; export function getVideoQualityOptions(options) { const maxStreamingBitrate = options.currentMaxBitrate; const videoBitRate = options.videoBitRate ?? -1; + const videoCodec = options.videoCodec; + let referenceBitRate = videoBitRate; // Quality options are indexed by bitrate. If you must duplicate them, make sure each of them are unique (by making the last digit a 1) // Question: the maxHeight field seems not be used anywhere, is it safe to remove those? @@ -36,13 +38,18 @@ export function getVideoQualityOptions(options) { } if (videoBitRate > 0 && videoBitRate < bitrateConfigurations[0].bitrate) { + // Slightly increase reference bitrate for high efficiency codecs when it is not too high + // Ideally we only need to do this for transcoding to h264, but we need extra api request to get that info which is not ideal for this + if (videoCodec && ['hevc', 'av1', 'vp9'].includes(videoCodec) && referenceBitRate <= 20000000) { + referenceBitRate *= 1.5; + } // Push one entry that has higher limit than video bitrate to allow using source bitrate when Auto is also limited - const sourceOptions = bitrateConfigurations.filter((c) => c.bitrate > videoBitRate).pop(); + const sourceOptions = bitrateConfigurations.filter((c) => c.bitrate > referenceBitRate).pop(); qualityOptions.push(sourceOptions); } bitrateConfigurations.forEach((c) => { - if (videoBitRate <= 0 || c.bitrate <= videoBitRate) { + if (videoBitRate <= 0 || c.bitrate <= referenceBitRate) { qualityOptions.push(c); } });