From: Zhao Zhili via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: support global_quality without qscale (PR #20382)
Message-ID: <175666209642.25.389137705508637907@463a07221176> (raw)
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
reply other threads:[~2025-08-31 17:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175666209642.25.389137705508637907@463a07221176 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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