From: Arjen Hiemstra Date: Thu, 20 Mar 2025 13:31:24 +0000 (+0100) Subject: [PATCH] Tweak encoding options for VP9 X-Git-Tag: archive/raspbian/6.3.6-1+rpi1^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bb5535d21395badbf0f8deb015646fed1291236e;p=kpipewire.git [PATCH] Tweak encoding options for VP9 Don't set both bitrate and CRF, as they are conflicting settings. Instead only set CRF. Also enable row-mt and avoid modifying the codec context in a function that is about options. Gbp-Pq: Name upstream_123ae0d2_Tweak-encoding-options-for-VP9.patch --- diff --git a/src/libvpxvp9encoder.cpp b/src/libvpxvp9encoder.cpp index d877023..a9220f4 100644 --- a/src/libvpxvp9encoder.cpp +++ b/src/libvpxvp9encoder.cpp @@ -60,16 +60,6 @@ bool LibVpxVp9Encoder::initialize(const QSize &size) m_avCodecContext->gop_size = fps * 2; - // TODO: Make bitrate depend on the framerate? More frames is more data. - // maxFramerate can apparently be changed while recording, so keep that in mind. - m_avCodecContext->bit_rate = std::round(area * 2); - m_avCodecContext->rc_min_rate = std::round(area); - m_avCodecContext->rc_max_rate = std::round(area * 3); - - m_avCodecContext->rc_buffer_size = m_avCodecContext->bit_rate; - - m_avCodecContext->thread_count = QThread::idealThreadCount(); - if (int result = avcodec_open2(m_avCodecContext, codec, &options); result < 0) { qCWarning(PIPEWIRERECORD_LOGGING) << "Could not open codec" << av_err2str(result); return false; @@ -100,8 +90,9 @@ AVDictionary *LibVpxVp9Encoder::buildEncodingOptions() if (m_quality) { crf = percentageToAbsoluteQuality(m_quality); } - m_avCodecContext->qmin = std::clamp(crf / 2, 0, crf); - m_avCodecContext->qmax = std::clamp(qRound(crf * 1.5), crf, 63); + + av_dict_set_int(&options, "qmin", std::clamp(crf / 2, 0, crf), 0); + av_dict_set_int(&options, "qmax", std::clamp(int(crf * 1.5), crf, 63), 0); av_dict_set_int(&options, "crf", crf, 0); // 0-4 are for Video-On-Demand with the good or best deadline. @@ -117,8 +108,7 @@ AVDictionary *LibVpxVp9Encoder::buildEncodingOptions() av_dict_set(&options, "tile-columns", "6", 0); av_dict_set(&options, "tile-rows", "2", 0); - // This should make things faster, but it only seems to consume 100MB more RAM. - // av_dict_set(&options, "row-mt", "1", 0); + av_dict_set(&options, "row-mt", "1", 0); av_dict_set(&options, "frame-parallel", "1", 0); return options;