Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Zhao Zhili <quinkblack@foxmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Zhao Zhili <zhilizhao@tencent.com>
Subject: [FFmpeg-devel] [PATCH v2 3/7] avcodec/mediacodecenc: add level option
Date: Wed,  7 Dec 2022 17:31:18 +0800
Message-ID: <tencent_3FE96A327F56AD8E38F9C0A9B7BC68FE000A@qq.com> (raw)
In-Reply-To: <20221207093122.553668-1-quinkblack@foxmail.com>

From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavcodec/mediacodecenc.c | 143 ++++++++++++++++++++++++++++++++++++-
 libavcodec/version.h       |   2 +-
 2 files changed, 142 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index ec0e0b3a86..2f78567451 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -80,6 +80,7 @@ typedef struct MediaCodecEncContext {
     AVFrame *frame;
 
     int bitrate_mode;
+    int level;
 } MediaCodecEncContext;
 
 enum {
@@ -233,6 +234,10 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
         ff_AMediaFormat_setInt32(format, "profile", ret);
     }
+    if (s->level > 0) {
+        av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
+        ff_AMediaFormat_setInt32(format, "level", s->level);
+    }
 
     ret = ff_AMediaCodec_getConfigureFlagEncode(s->codec);
     ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
@@ -541,17 +546,151 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = {              \
 };                                                                      \
 
 #if CONFIG_H264_MEDIACODEC_ENCODER
+
+enum MediaCodecAvcLevel {
+    AVCLevel1       = 0x01,
+    AVCLevel1b      = 0x02,
+    AVCLevel11      = 0x04,
+    AVCLevel12      = 0x08,
+    AVCLevel13      = 0x10,
+    AVCLevel2       = 0x20,
+    AVCLevel21      = 0x40,
+    AVCLevel22      = 0x80,
+    AVCLevel3       = 0x100,
+    AVCLevel31      = 0x200,
+    AVCLevel32      = 0x400,
+    AVCLevel4       = 0x800,
+    AVCLevel41      = 0x1000,
+    AVCLevel42      = 0x2000,
+    AVCLevel5       = 0x4000,
+    AVCLevel51      = 0x8000,
+    AVCLevel52      = 0x10000,
+    AVCLevel6       = 0x20000,
+    AVCLevel61      = 0x40000,
+    AVCLevel62      = 0x80000,
+};
+
 static const AVOption h264_options[] = {
     COMMON_OPTION
+    { "level", "Specify level",
+                OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
+    { "1",      "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1  },  0, 0, VE, "level" },
+    { "1b",     "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, "level" },
+    { "1.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, "level" },
+    { "1.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, "level" },
+    { "1.3",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, "level" },
+    { "2",      "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2  },  0, 0, VE, "level" },
+    { "2.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, "level" },
+    { "2.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, "level" },
+    { "3",      "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3  },  0, 0, VE, "level" },
+    { "3.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, "level" },
+    { "3.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, "level" },
+    { "4",      "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4  },  0, 0, VE, "level" },
+    { "4.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, "level" },
+    { "4.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, "level" },
+    { "5",      "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5  },  0, 0, VE, "level" },
+    { "5.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, "level" },
+    { "5.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, "level" },
+    { "6.0",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6  }, 0, 0, VE, "level" },
+    { "6.1",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, "level" },
+    { "6.2",    "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, "level" },
     { NULL, }
 };
+
 DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
-#endif
+
+#endif  // CONFIG_H264_MEDIACODEC_ENCODER
 
 #if CONFIG_HEVC_MEDIACODEC_ENCODER
+
+enum MediaCodecHevcLevel {
+    HEVCMainTierLevel1  = 0x1,
+    HEVCHighTierLevel1  = 0x2,
+    HEVCMainTierLevel2  = 0x4,
+    HEVCHighTierLevel2  = 0x8,
+    HEVCMainTierLevel21 = 0x10,
+    HEVCHighTierLevel21 = 0x20,
+    HEVCMainTierLevel3  = 0x40,
+    HEVCHighTierLevel3  = 0x80,
+    HEVCMainTierLevel31 = 0x100,
+    HEVCHighTierLevel31 = 0x200,
+    HEVCMainTierLevel4  = 0x400,
+    HEVCHighTierLevel4  = 0x800,
+    HEVCMainTierLevel41 = 0x1000,
+    HEVCHighTierLevel41 = 0x2000,
+    HEVCMainTierLevel5  = 0x4000,
+    HEVCHighTierLevel5  = 0x8000,
+    HEVCMainTierLevel51 = 0x10000,
+    HEVCHighTierLevel51 = 0x20000,
+    HEVCMainTierLevel52 = 0x40000,
+    HEVCHighTierLevel52 = 0x80000,
+    HEVCMainTierLevel6  = 0x100000,
+    HEVCHighTierLevel6  = 0x200000,
+    HEVCMainTierLevel61 = 0x400000,
+    HEVCHighTierLevel61 = 0x800000,
+    HEVCMainTierLevel62 = 0x1000000,
+    HEVCHighTierLevel62 = 0x2000000,
+};
+
 static const AVOption hevc_options[] = {
     COMMON_OPTION
+    { "level", "Specify tier and level",
+                OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
+    { "m1",    "Main tier level 1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1  },  0, 0, VE,  "level" },
+    { "h1",    "High tier level 1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1  },  0, 0, VE,  "level" },
+    { "m2",    "Main tier level 2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2  },  0, 0, VE,  "level" },
+    { "h2",    "High tier level 2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2  },  0, 0, VE,  "level" },
+    { "m2.1",  "Main tier level 2.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 },  0, 0, VE,  "level" },
+    { "h2.1",  "High tier level 2.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 },  0, 0, VE,  "level" },
+    { "m3",    "Main tier level 3",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3  },  0, 0, VE,  "level" },
+    { "h3",    "High tier level 3",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3  },  0, 0, VE,  "level" },
+    { "m3.1",  "Main tier level 3.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 },  0, 0, VE,  "level" },
+    { "h3.1",  "High tier level 3.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 },  0, 0, VE,  "level" },
+    { "m4",    "Main tier level 4",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4  },  0, 0, VE,  "level" },
+    { "h4",    "High tier level 4",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4  },  0, 0, VE,  "level" },
+    { "m4.1",  "Main tier level 4.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 },  0, 0, VE,  "level" },
+    { "h4.1",  "High tier level 4.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 },  0, 0, VE,  "level" },
+    { "m5",    "Main tier level 5",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5  },  0, 0, VE,  "level" },
+    { "h5",    "High tier level 5",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5  },  0, 0, VE,  "level" },
+    { "m5.1",  "Main tier level 5.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 },  0, 0, VE,  "level" },
+    { "h5.1",  "High tier level 5.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 },  0, 0, VE,  "level" },
+    { "m5.2",  "Main tier level 5.2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 },  0, 0, VE,  "level" },
+    { "h5.2",  "High tier level 5.2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 },  0, 0, VE,  "level" },
+    { "m6",    "Main tier level 6",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6  },  0, 0, VE,  "level" },
+    { "h6",    "High tier level 6",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6  },  0, 0, VE,  "level" },
+    { "m6.1",  "Main tier level 6.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 },  0, 0, VE,  "level" },
+    { "h6.1",  "High tier level 6.1",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 },  0, 0, VE,  "level" },
+    { "m6.2",  "Main tier level 6.2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 },  0, 0, VE,  "level" },
+    { "h6.2",  "High tier level 6.2",
+                0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 },  0, 0, VE,  "level" },
     { NULL, }
 };
+
 DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
-#endif
+
+#endif  // CONFIG_HEVC_MEDIACODEC_ENCODER
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 527b4dbd0b..61bdf5806b 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 102
+#define LIBAVCODEC_VERSION_MICRO 103
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
-- 
2.25.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".

  parent reply	other threads:[~2022-12-07  9:32 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20221207093122.553668-1-quinkblack@foxmail.com>
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 1/7] avcodec/mediacodecenc: make each encoder has its own option Zhao Zhili
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 2/7] avcodec/mediacodecenc: add bitrate_mode option Zhao Zhili
2022-12-07  9:31 ` Zhao Zhili [this message]
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 4/7] avcodec/mediacodecenc: use bsf to handle crop Zhao Zhili
2022-12-09 17:22   ` [FFmpeg-devel] [PATCH v3 3/7] " Zhao Zhili
2022-12-12 15:27     ` Tomas Härdin
2022-12-13  3:20       ` "zhilizhao(赵志立)"
2022-12-14 17:08         ` Tomas Härdin
2022-12-14 17:19           ` Tomas Härdin
2022-12-14 17:37           ` Zhao Zhili
2022-12-14 17:43             ` Zhao Zhili
2022-12-20 18:24             ` Tomas Härdin
2022-12-21  7:17               ` "zhilizhao(赵志立)"
2022-12-21 10:06                 ` Tomas Härdin
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 5/7] avcodec/mediacodecenc: remove the strategy to create DTS Zhao Zhili
2022-12-12 15:28   ` Tomas Härdin
2022-12-13  2:55     ` "zhilizhao(赵志立)"
2022-12-14 17:31       ` Tomas Härdin
2023-01-04 10:16   ` Anton Khirnov
2023-01-04 11:31     ` [FFmpeg-devel] [Internet]Re: " "zhilizhao(赵志立)"
2023-01-04 13:59       ` Tomas Härdin
2023-01-04 14:46         ` Zhao Zhili
2023-01-04 15:15           ` Anton Khirnov
2023-01-04 16:12             ` Zhao Zhili
2023-01-05  8:07               ` Anton Khirnov
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 6/7] avcodec/mediacodecenc: add max-bframes support Zhao Zhili
2022-12-07  9:31 ` [FFmpeg-devel] [PATCH v2 7/7] avcodec/mediacodecenc: add pts_as_dts option Zhao Zhili

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=tencent_3FE96A327F56AD8E38F9C0A9B7BC68FE000A@qq.com \
    --to=quinkblack@foxmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=zhilizhao@tencent.com \
    /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