From 13aa659a0255326abc547e856a0bab11c194cd2f Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Mon, 7 Nov 2022 01:21:22 +0000 Subject: [PATCH 1/2] Revert "video: use a better vbv-bufsize & correct software bitrate calculation" This reverts commit 1b6bf8fa3461f8cf0d8385cb09798ef2cdef171b. --- src/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index e847b629f4e..f25b28f8836 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -978,9 +978,9 @@ std::optional make_session(const encoder_t &encoder, const config_t & } if(video_format[encoder_t::CBR]) { - auto bitrate = config.bitrate * (hardware ? 1000 : 800); // software bitrate overshoots by ~20% + auto bitrate = config.bitrate * 1000; ctx->rc_max_rate = bitrate; - ctx->rc_buffer_size = bitrate / 10; + ctx->rc_buffer_size = bitrate / config.framerate; ctx->bit_rate = bitrate; ctx->rc_min_rate = bitrate; } From 9cb47a0a01aa58cd63462e75ed6e89380326919b Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Mon, 7 Nov 2022 01:23:00 +0000 Subject: [PATCH 2/2] video: increase bufsize by 1.5x to avoid degradation with high libx264 slice count If the libx264 encoder is configured to use >4 slices, the existing bufsize (bitrate / framerate) is set too low, causing a quality degradation and failure for the encoder to attain the target bitrate. A previous commit set this to a larger value (bitrate / 10), but this seemed to cause issues with the RPI3 hardware decoder; see: https://github.com/LizardByte/Sunshine/issues/478 Ref: https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate "Specifying too small -bufsize would cause ffmpeg to degrade the output image quality, because it would have to (frequently) conform to the limitations and would not have enough of a free space to use some optimizations (for example, optimizations based on the frame repetitions and similar), because the buffer would not contain enough frames for the optimizations to be effective." --- src/video.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video.cpp b/src/video.cpp index f25b28f8836..30dda46d7eb 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -980,7 +980,7 @@ std::optional make_session(const encoder_t &encoder, const config_t & if(video_format[encoder_t::CBR]) { auto bitrate = config.bitrate * 1000; ctx->rc_max_rate = bitrate; - ctx->rc_buffer_size = bitrate / config.framerate; + ctx->rc_buffer_size = bitrate / ((config.framerate * 10) / 15); ctx->bit_rate = bitrate; ctx->rc_min_rate = bitrate; }