[FFmpeg-cvslog] avcodec/mediacodec: add vp9 encoder using mediacodec
Samuel Raposo Vieira Mira
git at videolan.org
Sun Apr 2 10:17:28 EEST 2023
ffmpeg | branch: master | Samuel Raposo Vieira Mira <samuel.mira at qt.io> | Mon Mar 27 15:21:34 2023 +0000| [139f3352ed4bbe762c6f87b2443c9378c2beaae3] | committer: Zhao Zhili
avcodec/mediacodec: add vp9 encoder using mediacodec
The only encoders avaliable using mediacodec were h264 and hevc. This
patch adds the vp9 encoder.
Signed-off-by: Samuel Mira <samuel.mira at qt.io<mailto: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=139f3352ed4bbe762c6f87b2443c9378c2beaae3
---
configure | 3 ++
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/mediacodec_wrapper.c | 24 ++++++++++++++++
libavcodec/mediacodecenc.c | 61 +++++++++++++++++++++++++++++++++++++++++
libavcodec/version.h | 4 +--
6 files changed, 92 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index fe367462a1..f4afa00a6e 100755
--- a/configure
+++ b/configure
@@ -3248,6 +3248,9 @@ vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
vp9_cuvid_decoder_deps="cuvid"
vp9_mediacodec_decoder_deps="mediacodec"
+vp9_mediacodec_decoder_extralibs="-landroid"
+vp9_mediacodec_encoder_deps="mediacodec"
+vp9_mediacodec_encoder_extralibs="-landroid"
vp9_qsv_decoder_select="qsvdec"
vp9_rkmpp_decoder_deps="rkmpp"
vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 711d2690d0..fd0a89aa7f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -774,6 +774,7 @@ OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9data.o vp9dsp.o vp9lpf.o vp9r
vp9dsp_8bpp.o vp9dsp_10bpp.o vp9dsp_12bpp.o
OBJS-$(CONFIG_VP9_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER) += mediacodecdec.o
+OBJS-$(CONFIG_VP9_MEDIACODEC_ENCODER) += mediacodecenc.o
OBJS-$(CONFIG_VP9_RKMPP_DECODER) += rkmppdec.o
OBJS-$(CONFIG_VP9_VAAPI_ENCODER) += vaapi_encode_vp9.o
OBJS-$(CONFIG_VP9_QSV_ENCODER) += qsvenc_vp9.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 3cbb93347b..ea6edd0195 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -884,6 +884,7 @@ extern const FFCodec ff_vp8_v4l2m2m_encoder;
extern const FFCodec ff_vp8_vaapi_encoder;
extern const FFCodec ff_vp9_cuvid_decoder;
extern const FFCodec ff_vp9_mediacodec_decoder;
+extern const FFCodec ff_vp9_mediacodec_encoder;
extern const FFCodec ff_vp9_qsv_decoder;
extern const FFCodec ff_vp9_vaapi_encoder;
extern const FFCodec ff_vp9_qsv_encoder;
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index d1fb640ec2..b13211d435 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -319,10 +319,23 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
static const int HEVCProfileMain10HDR10 = 0x1000;
static const int HEVCProfileMain10HDR10Plus = 0x2000;
+ static const int VP9Profile0 = 0x01;
+ static const int VP9Profile1 = 0x02;
+ static const int VP9Profile2 = 0x04;
+ static const int VP9Profile3 = 0x08;
+ static const int VP9Profile2HDR = 0x1000;
+ static const int VP9Profile3HDR = 0x2000;
+ static const int VP9Profile2HDR10Plus = 0x4000;
+ static const int VP9Profile3HDR10Plus = 0x8000;
+
// Unused yet.
(void)AVCProfileConstrainedHigh;
(void)HEVCProfileMain10HDR10;
(void)HEVCProfileMain10HDR10Plus;
+ (void)VP9Profile2HDR;
+ (void)VP9Profile3HDR;
+ (void)VP9Profile2HDR10Plus;
+ (void)VP9Profile3HDR10Plus;
if (avctx->codec_id == AV_CODEC_ID_H264) {
switch(avctx->profile) {
@@ -357,6 +370,17 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
case FF_PROFILE_HEVC_MAIN_10:
return HEVCProfileMain10;
}
+ } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
+ switch (avctx->profile) {
+ case FF_PROFILE_VP9_0:
+ return VP9Profile0;
+ case FF_PROFILE_VP9_1:
+ return VP9Profile1;
+ case FF_PROFILE_VP9_2:
+ return VP9Profile2;
+ case FF_PROFILE_VP9_3:
+ return VP9Profile3;
+ }
}
return -1;
diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index 2ab56597fe..c7e2beb1ae 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -164,6 +164,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx)
case AV_CODEC_ID_HEVC:
codec_mime = "video/hevc";
break;
+ case AV_CODEC_ID_VP9:
+ codec_mime = "video/x-vnd.on2.vp9";
+ break;
default:
av_assert0(0);
}
@@ -764,3 +767,61 @@ static const AVOption hevc_options[] = {
DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
#endif // CONFIG_HEVC_MEDIACODEC_ENCODER
+
+#if CONFIG_VP9_MEDIACODEC_ENCODER
+
+enum MediaCodecVP9Level {
+ VP9Level1 = 0x1,
+ VP9Level11 = 0x2,
+ VP9Level2 = 0x4,
+ VP9Level21 = 0x8,
+ VP9Level3 = 0x10,
+ VP9Level31 = 0x20,
+ VP9Level4 = 0x40,
+ VP9Level41 = 0x80,
+ VP9Level5 = 0x100,
+ VP9Level51 = 0x200,
+ VP9Level52 = 0x400,
+ VP9Level6 = 0x800,
+ VP9Level61 = 0x1000,
+ VP9Level62 = 0x2000,
+};
+
+static const AVOption vp9_options[] = {
+ COMMON_OPTION
+ { "level", "Specify tier and level",
+ OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
+ { "1", "Level 1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, "level" },
+ { "1.1", "Level 1.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, "level" },
+ { "2", "Level 2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, "level" },
+ { "2.1", "Level 2.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, "level" },
+ { "3", "Level 3",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, "level" },
+ { "3.1", "Level 3.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, "level" },
+ { "4", "Level 4",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, "level" },
+ { "4.1", "Level 4.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, "level" },
+ { "5", "Level 5",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, "level" },
+ { "5.1", "Level 5.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, "level" },
+ { "5.2", "Level 5.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, "level" },
+ { "6", "Level 6",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, "level" },
+ { "6.1", "Level 4.1",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, "level" },
+ { "6.2", "Level 6.2",
+ 0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, "level" },
+ { NULL, }
+};
+
+DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9)
+
+#endif // CONFIG_VP9_MEDIACODEC_ENCODER
diff --git a/libavcodec/version.h b/libavcodec/version.h
index ecb096f38b..37c4c39451 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 7
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR 8
+#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list