* [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: support global_quality without qscale (PR #20382)
@ 2025-08-31 17:42 Zhao Zhili via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: Zhao Zhili via ffmpeg-devel @ 2025-08-31 17:42 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
PR #20382 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20382
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20382.patch
>From 2e680445ec3975462e4ba3af0e8e1840b0e03bf1 Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
Date: Mon, 1 Sep 2025 01:17:08 +0800
Subject: [PATCH 1/2] avcodec/videotoolboxenc: fix the loss of precision when
calculating quality
---
libavcodec/videotoolboxenc.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index b748ecda61..ff8e636c88 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1185,9 +1185,7 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
VTEncContext *vtctx = avctx->priv_data;
SInt32 bit_rate = avctx->bit_rate;
SInt32 max_rate = avctx->rc_max_rate;
- Float32 quality = avctx->global_quality / FF_QP2LAMBDA;
CFNumberRef bit_rate_num;
- CFNumberRef quality_num;
CFNumberRef bytes_per_second;
CFNumberRef one_second;
CFArrayRef data_rate_limits;
@@ -1248,10 +1246,11 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
}
if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
- quality = quality >= 100 ? 1.0 : quality / 100;
- quality_num = CFNumberCreate(kCFAllocatorDefault,
- kCFNumberFloat32Type,
- &quality);
+ Float32 quality = FFMIN(avctx->global_quality / 100.0f / FF_QP2LAMBDA,
+ 1.0f);
+ CFNumberRef quality_num = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberFloat32Type,
+ &quality);
if (!quality_num) return AVERROR(ENOMEM);
status = VTSessionSetProperty(vtctx->session,
--
2.49.1
>From 8ea46fe2abcc2c9417707d7b130c99e4546e75dc Mon Sep 17 00:00:00 2001
From: Zhao Zhili <zhilizhao@tencent.com>
Date: Mon, 1 Sep 2025 01:36:25 +0800
Subject: [PATCH 2/2] avcodec/videotoolboxenc: support global_quality without
qscale
---
libavcodec/videotoolboxenc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index ff8e636c88..ef8a729992 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -1245,9 +1245,10 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
return AVERROR_EXTERNAL;
}
- if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
- Float32 quality = FFMIN(avctx->global_quality / 100.0f / FF_QP2LAMBDA,
- 1.0f);
+ if (avctx->flags & AV_CODEC_FLAG_QSCALE || avctx->global_quality > 0) {
+ float factor = (avctx->flags & AV_CODEC_FLAG_QSCALE) ?
+ FF_QP2LAMBDA * 100.0f : 100.0f;
+ Float32 quality = FFMIN(avctx->global_quality / factor, 1.0f);
CFNumberRef quality_num = CFNumberCreate(kCFAllocatorDefault,
kCFNumberFloat32Type,
&quality);
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-08-31 17:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-31 17:42 [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: support global_quality without qscale (PR #20382) Zhao Zhili via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git