Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/d3d12va_encode: add max_frame_size option (PR #20287)
@ 2025-08-19 14:49 Tong Wu via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Tong Wu via ffmpeg-devel @ 2025-08-19 14:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Tong Wu

PR #20287 opened by Tong Wu (tong1wu)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20287
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20287.patch

Add the max_frame_size option to support setting max frame size in
bytes. Max frame size is the maximum cap in the bitrate algorithm per
each encoded frame.

Signed-off-by: Tong Wu <wutong1208@outlook.com>


From 8c2c9f41182605b3c13cc22397dfe37e2a737078 Mon Sep 17 00:00:00 2001
From: Tong Wu <wutong1208@outlook.com>
Date: Tue, 19 Aug 2025 22:42:25 +0800
Subject: [PATCH] avcodec/d3d12va_encode: add max_frame_size option

Add the max_frame_size option to support setting max frame size in
bytes. Max frame size is the maximum cap in the bitrate algorithm per
each encoded frame.

Signed-off-by: Tong Wu <wutong1208@outlook.com>
---
 libavcodec/d3d12va_encode.c      | 15 +++++++++++++++
 libavcodec/d3d12va_encode.h      | 11 +++++++++++
 libavcodec/d3d12va_encode_hevc.c |  1 +
 3 files changed, 27 insertions(+)

diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index 880002ce55..1481875ac1 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -993,6 +993,11 @@ rc_mode_found:
                 ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
             }
 
+            if (ctx->max_frame_size > 0) {
+                cbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
+                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            }
+
             ctx->rc.ConfigParams.pConfiguration_CBR = cbr_ctl;
             break;
 
@@ -1016,6 +1021,11 @@ rc_mode_found:
                 ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
             }
 
+            if (ctx->max_frame_size > 0) {
+                vbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
+                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            }
+
             ctx->rc.ConfigParams.pConfiguration_VBR = vbr_ctl;
             break;
 
@@ -1037,6 +1047,11 @@ rc_mode_found:
                 ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_QP_RANGE;
             }
 
+            if (ctx->max_frame_size > 0) {
+                qvbr_ctl->MaxFrameBitSize = ctx->max_frame_size * 8;
+                ctx->rc.Flags |= D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE;
+            }
+
             ctx->rc.ConfigParams.pConfiguration_QVBR = qvbr_ctl;
             break;
 
diff --git a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h
index 3b0b8153d5..cba648183b 100644
--- a/libavcodec/d3d12va_encode.h
+++ b/libavcodec/d3d12va_encode.h
@@ -149,6 +149,11 @@ typedef struct D3D12VAEncodeContext {
      */
     const struct D3D12VAEncodeType *codec;
 
+    /**
+     * Max frame size
+     */
+    int max_frame_size;
+
     /**
      * Explicitly set RC mode (otherwise attempt to pick from
      * available modes).
@@ -317,6 +322,12 @@ int ff_d3d12va_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
 int ff_d3d12va_encode_init(AVCodecContext *avctx);
 int ff_d3d12va_encode_close(AVCodecContext *avctx);
 
+#define D3D12VA_ENCODE_COMMON_OPTIONS \
+    { "max_frame_size", \
+      "Maximum frame size (in bytes)",\
+      OFFSET(common.max_frame_size), AV_OPT_TYPE_INT, \
+      { .i64 = 0 }, 0, INT_MAX, FLAGS }
+
 #define D3D12VA_ENCODE_RC_MODE(name, desc) \
     { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \
       0, 0, FLAGS, .unit = "rc_mode" }
diff --git a/libavcodec/d3d12va_encode_hevc.c b/libavcodec/d3d12va_encode_hevc.c
index ce5d1bf110..31e74540a3 100644
--- a/libavcodec/d3d12va_encode_hevc.c
+++ b/libavcodec/d3d12va_encode_hevc.c
@@ -705,6 +705,7 @@ static int d3d12va_encode_hevc_close(AVCodecContext *avctx)
 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 static const AVOption d3d12va_encode_hevc_options[] = {
     HW_BASE_ENCODE_COMMON_OPTIONS,
+    D3D12VA_ENCODE_COMMON_OPTIONS,
     D3D12VA_ENCODE_RC_OPTIONS,
 
     { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-08-19 14:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-19 14:49 [FFmpeg-devel] [PATCH] avcodec/d3d12va_encode: add max_frame_size option (PR #20287) Tong Wu 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