Commit 46560047e9 for ffmpeg
commit 46560047e91c5d2ce3905f9a7239b261c06047a3
Author: nyanmisaka <nst799610810@gmail.com>
Date: Wed Sep 23 14:35:09 2026 +0800
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 <nst799610810@gmail.com>
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index aef27e2a8f..fb8e19deef 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1563,9 +1563,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) {