PR #24644 opened by nyanmisaka
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24644
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24644.patch

# Summary of changes

The `global_quality` is not stored in `Encoder` when `qscale` is not set.
Some encoders rely on it to switch the rate control mode from CQP to ICQ.

```
ffmpeg -v verbose -f lavfi -i nullsrc=s=1920x1080,format=nv12 \
-c:v h264_qsv -global_quality 20 -t 1 -f null -
...
[h264_qsv @ 00000234c99847c0] Using the constant quantization parameter (CQP) 
by default.
Please use the global_quality option and other options for a quality-based mode 
or the b option
and other options for a bitrate-based mode if the default is not the desired 
choice.

[h264_qsv @ 00000234c99847c0] Using the constant quantization parameter (CQP) 
ratecontrol method
```

Fixes 7d905abec6ab565ac3afbaa7840ed278a330eab2

Signed-off-by: nyanmisaka <[email protected]>


>From 9f6bb3d2fe8f1083c8adac1f2788e33fa9088c18 Mon Sep 17 00:00:00 2001
From: nyanmisaka <[email protected]>
Date: Wed, 23 Sep 2026 14:35:09 +0800
Subject: [PATCH] fftools/ffmpeg_mux_init: fix -global_quality being lost

The `global_quality` is not stored in `Encoder` when `qscale` is not set.
Some encoders rely on it to switch the rate control mode from CQP to ICQ.

```
ffmpeg -v verbose -f lavfi -i nullsrc=s=1920x1080,format=nv12 \
-c:v h264_qsv -global_quality 20 -t 1 -f null -
...
[h264_qsv @ 00000234c99847c0] Using the constant quantization parameter (CQP) 
by default.
Please use the global_quality option and other options for a quality-based mode 
or the b option
and other options for a bitrate-based mode if the default is not the desired 
choice.

[h264_qsv @ 00000234c99847c0] Using the constant quantization parameter (CQP) 
ratecontrol method
```

Fixes 7d905abec6ab565ac3afbaa7840ed278a330eab2

Signed-off-by: nyanmisaka <[email protected]>
---
 fftools/ffmpeg_mux_init.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index a01a6b756e..c06fe24d6e 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1557,9 +1557,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
     }
 
     opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);
-    if (ost->enc && qscale >= 0) {
-        ost->enc->flags          |= AV_CODEC_FLAG_QSCALE;
-        ost->enc->global_quality  = FF_QP2LAMBDA * qscale;
+    if (ost->enc) {
+        if (qscale >= 0) {
+            ost->enc->flags          |= AV_CODEC_FLAG_QSCALE;
+            ost->enc->global_quality  = FF_QP2LAMBDA * qscale;
+        } else
+            ost->enc->global_quality  = ost->enc->enc_ctx->global_quality;
     }
 
     if (ms->sch_idx >= 0) {
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to