diff mbox series

[FFmpeg-devel,1/7] avcodec/mediacodecenc: add bitrate_mode option

Message ID tencent_9194CFE0D52F2763B8AF9624CD5D2007CD07@qq.com
State New
Headers show
Series [FFmpeg-devel,1/7] avcodec/mediacodecenc: add bitrate_mode option | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Zhao Zhili Dec. 4, 2022, 5:12 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavcodec/mediacodecenc.c | 25 +++++++++++++++++++++++++
 libavcodec/version.h       |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 69246ad693..c8d8f84e46 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -39,6 +39,17 @@ 
 #define INPUT_DEQUEUE_TIMEOUT_US 8000
 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
 
+enum BitrateMode {
+    /* Constant quality mode */
+    BITRATE_MODE_CQ = 0,
+    /* Variable bitrate mode */
+    BITRATE_MODE_VBR = 1,
+    /* Constant bitrate mode */
+    BITRATE_MODE_CBR = 2,
+    /* Constant bitrate mode with frame drops */
+    BITRATE_MODE_CBR_FD = 3,
+};
+
 typedef struct MediaCodecEncContext {
     AVClass *avclass;
     FFAMediaCodec *codec;
@@ -67,6 +78,8 @@  typedef struct MediaCodecEncContext {
     int eof_sent;
 
     AVFrame *frame;
+
+    int bitrate_mode;
 } MediaCodecEncContext;
 
 enum {
@@ -193,6 +206,8 @@  static av_cold int mediacodec_init(AVCodecContext *avctx)
 
     if (avctx->bit_rate)
         ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
+    if (s->bitrate_mode >= 0)
+        ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
     // frame-rate and i-frame-interval are required to configure codec
     if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
         s->fps = avctx->framerate.num / avctx->framerate.den;
@@ -485,6 +500,16 @@  static const AVOption common_options[] = {
                     OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
     { "codec_name", "Select codec by name",
                     OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
+    { "bitrate_mode", "Bitrate control method",
+                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },
+    { "cq", "Constant quality mode",
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },
+    { "vbr", "Variable bitrate mode",
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },
+    { "cbr", "Constant bitrate mode",
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },
+    { "cbr_fd", "Constant bitrate mode with frame drops",
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },
     { NULL },
 };
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 9e66920593..527b4dbd0b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@ 
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  54
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \