diff options
| author | nyanmisaka <nst799610810@gmail.com> | 2026-05-02 20:14:51 +0800 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2026-05-03 12:25:33 +0200 |
| commit | d9ced0d6399c82ddad9e983605bb0d828a608e63 (patch) | |
| tree | 3c5dbb08550fbb71df456b46143f6d940f020edd /MediaBrowser.Controller/MediaEncoding | |
| parent | f5f75ed2e1b10dc1f4e55d5cdd9dd7fd69ea8f2b (diff) | |
Use strict QSV CPB size for less powerful H.264 decoder
Signed-off-by: nyanmisaka <nst799610810@gmail.com>
Diffstat (limited to 'MediaBrowser.Controller/MediaEncoding')
| -rw-r--r-- | MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 117f376724..a0e04eae63 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -1621,13 +1621,25 @@ namespace MediaBrowser.Controller.MediaEncoding mbbrcOpt = " -mbbrc 1"; } + // Some less powerful H.264 HW decoders require strict CPB size + // So bufsize optimizations should not be applied to them + int factor = 2; + var codec = state.ActualOutputVideoCodec; + var level = state.GetRequestedLevel(codec); + if (string.Equals(codec, "h264", StringComparison.OrdinalIgnoreCase) + && double.TryParse(level, CultureInfo.InvariantCulture, out double requestedLevel) + && requestedLevel < 51) + { + factor = 1; + } + // Set (maxrate == bitrate + 1) to trigger VBR for better bitrate allocation // Set (rc_init_occupancy == 2 * bitrate) and (bufsize == 4 * bitrate) to deal with drastic scene changes // Use long arithmetic and clamp to int.MaxValue to prevent int32 overflow // (e.g. bitrate * 4 wraps to a negative value for bitrates above ~537 million) int qsvMaxrate = (int)Math.Min((long)bitrate + 1, int.MaxValue); - int qsvInitOcc = (int)Math.Min((long)bitrate * 2, int.MaxValue); - int qsvBufsize = (int)Math.Min((long)bitrate * 4, int.MaxValue); + int qsvInitOcc = (int)Math.Min((long)bitrate * 1 * factor, int.MaxValue); + int qsvBufsize = (int)Math.Min((long)bitrate * 2 * factor, int.MaxValue); return FormattableString.Invariant($"{mbbrcOpt} -b:v {bitrate} -maxrate {qsvMaxrate} -rc_init_occupancy {qsvInitOcc} -bufsize {qsvBufsize}"); } |
