[FFmpeg-cvslog] avcodec/mediacodec: Add AV1 encoder
Samuel Mira
git at videolan.org
Wed May 17 06:36:04 EEST 2023
ffmpeg | branch: master | Samuel Mira <samuel.mira at qt.io> | Tue Apr 25 19:37:05 2023 +0300| [acd37fd5667ae1f0ed988ed45d7af3a41d766d80] | committer: Zhao Zhili
avcodec/mediacodec: Add AV1 encoder
Connected FFmpeg to Mediacodec AV1 encoder
Signed-off-by: Samuel Mira <samuel.mira at qt.io>
Signed-off-by: Zhao Zhili <zhilizhao at tencent.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=acd37fd5667ae1f0ed988ed45d7af3a41d766d80
---
configure | 1 +
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/mediacodec_wrapper.c | 19 +++++++++
libavcodec/mediacodecenc.c | 91 +++++++++++++++++++++++++++++++++++++++++
libavcodec/version.h | 2 +-
6 files changed, 114 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
index bb7be67676..0a60deac65 100755
--- a/configure
+++ b/configure
@@ -3162,6 +3162,7 @@ aac_mf_encoder_deps="mediafoundation"
ac3_mf_encoder_deps="mediafoundation"
av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
av1_mediacodec_decoder_deps="mediacodec"
+av1_mediacodec_encoder_deps="mediacodec"
av1_nvenc_encoder_deps="nvenc NV_ENC_PIC_PARAMS_AV1"
av1_nvenc_encoder_select="atsc_a53"
h263_v4l2m2m_decoder_deps="v4l2_m2m h263_v4l2_m2m"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4d59411662..2288c6c2d7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -253,6 +253,7 @@ OBJS-$(CONFIG_AURA2_DECODER) += aura.o
OBJS-$(CONFIG_AV1_DECODER) += av1dec.o
OBJS-$(CONFIG_AV1_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER) += mediacodecdec.o
+OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER) += mediacodecenc.o
OBJS-$(CONFIG_AV1_NVENC_ENCODER) += nvenc_av1.o nvenc.o
OBJS-$(CONFIG_AV1_QSV_ENCODER) += qsvenc_av1.o
OBJS-$(CONFIG_AVRN_DECODER) += avrndec.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8eeed34e57..f583aad860 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -836,6 +836,7 @@ extern const FFCodec ff_libaom_av1_decoder;
extern const FFCodec ff_av1_decoder;
extern const FFCodec ff_av1_cuvid_decoder;
extern const FFCodec ff_av1_mediacodec_decoder;
+extern const FFCodec ff_av1_mediacodec_encoder;
extern const FFCodec ff_av1_nvenc_encoder;
extern const FFCodec ff_av1_qsv_decoder;
extern const FFCodec ff_av1_qsv_encoder;
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 1c29bb7406..eb69ad7eaf 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -345,6 +345,12 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
static const int MPEG4ProfileAdvancedScalable = 0x4000;
static const int MPEG4ProfileAdvancedSimple = 0x8000;
+
+ static const int AV1ProfileMain8 = 0x1;
+ static const int AV1ProfileMain10 = 0x2;
+ static const int AV1ProfileMain10HDR10 = 0x1000;
+ static const int AV1ProfileMain10HDR10Plus = 0x2000;
+
// Unused yet.
(void)AVCProfileConstrainedHigh;
(void)HEVCProfileMain10HDR10;
@@ -353,6 +359,9 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
(void)VP9Profile3HDR;
(void)VP9Profile2HDR10Plus;
(void)VP9Profile3HDR10Plus;
+ (void)AV1ProfileMain10;
+ (void)AV1ProfileMain10HDR10;
+ (void)AV1ProfileMain10HDR10Plus;
if (avctx->codec_id == AV_CODEC_ID_H264) {
switch(avctx->profile) {
@@ -436,6 +445,16 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
default:
break;
}
+ } else if(avctx->codec_id == AV_CODEC_ID_AV1) {
+ switch (avctx->profile)
+ {
+ case FF_PROFILE_AV1_MAIN:
+ return AV1ProfileMain8;
+ case FF_PROFILE_AV1_HIGH:
+ case FF_PROFILE_AV1_PROFESSIONAL:
+ default:
+ break;
+ }
}
return -1;
diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index e4b583a542..2b7bef444e 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -170,6 +170,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
case AV_CODEC_ID_MPEG4:
codec_mime = "video/mp4v-es";
break;
+ case AV_CODEC_ID_AV1:
+ codec_mime = "video/av01";
+ break;
default:
av_assert0(0);
}
@@ -878,3 +881,91 @@ static const AVOption mpeg4_options[] = {
DECLARE_MEDIACODEC_ENCODER(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4)
#endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
+
+#if CONFIG_AV1_MEDIACODEC_ENCODER
+
+enum MediaCodecAV1Level {
+ AV1Level2 = 0x1,
+ AV1Level21 = 0x2,
+ AV1Level22 = 0x4,
+ AV1Level23 = 0x8,
+ AV1Level3 = 0x10,
+ AV1Level31 = 0x20,
+ AV1Level32 = 0x40,
+ AV1Level33 = 0x80,
+ AV1Level4 = 0x100,
+ AV1Level41 = 0x200,
+ AV1Level42 = 0x400,
+ AV1Level43 = 0x800,
+ AV1Level5 = 0x1000,
+ AV1Level51 = 0x2000,
+ AV1Level52 = 0x4000,
+ AV1Level53 = 0x8000,
+ AV1Level6 = 0x10000,
+ AV1Level61 = 0x20000,
+ AV1Level62 = 0x40000,
+ AV1Level63 = 0x80000,
+ AV1Level7 = 0x100000,
+ AV1Level71 = 0x200000,
+ AV1Level72 = 0x400000,
+ AV1Level73 = 0x800000,
+};
+
+static const AVOption av1_options[] = {
+ COMMON_OPTION
+ { "level", "Specify tier and level",
+ OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
+ { "2", "Level 2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, "level" },
+ { "2.1", "Level 2.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, "level" },
+ { "2.2", "Level 2.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, "level" },
+ { "2.3", "Level 2.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, "level" },
+ { "3", "Level 3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, "level" },
+ { "3.1", "Level 3.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, "level" },
+ { "3.2", "Level 3.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, "level" },
+ { "3.3", "Level 3.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, "level" },
+ { "4", "Level 4",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, "level" },
+ { "4.1", "Level 4.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, "level" },
+ { "4.2", "Level 4.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, "level" },
+ { "4.3", "Level 4.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, "level" },
+ { "5", "Level 5",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, "level" },
+ { "5.1", "Level 5.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, "level" },
+ { "5.2", "Level 5.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, "level" },
+ { "5.3", "Level 5.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, "level" },
+ { "6", "Level 6",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, "level" },
+ { "6.1", "Level 6.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, "level" },
+ { "6.2", "Level 6.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, "level" },
+ { "6.3", "Level 6.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, "level" },
+ { "7", "Level 7",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, "level" },
+ { "7.1", "Level 7.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, "level" },
+ { "7.2", "Level 7.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, "level" },
+ { "7.3", "Level 7.3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, "level" },
+ { NULL, }
+};
+
+DECLARE_MEDIACODEC_ENCODER(av1, "AV1", AV_CODEC_ID_AV1)
+
+#endif // CONFIG_AV1_MEDIACODEC_ENCODER
diff --git a/libavcodec/version.h b/libavcodec/version.h
index da2264a097..755c90bbc1 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 12
+#define LIBAVCODEC_VERSION_MINOR 13
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list