[FFmpeg-devel] [PATCH 1/2] avcodec/mediacodec add vp9 encoder using mediacodec
Samuel Raposo Vieira Mira
samuel.mira at qt.io
Mon Mar 27 18:21:34 EEST 2023
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>>
---
configure | 3 ++
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/mediacodec_wrapper.c | 24 +++++++++++++
libavcodec/mediacodecenc.c | 61 +++++++++++++++++++++++++++++++++
5 files changed, 90 insertions(+)
diff --git a/configure b/configure
index cec001fb16..101bc7b2f1 100755
--- a/configure
+++ b/configure
@@ -3246,6 +3246,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 408ecd1e31..3d213014c6 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 385ee34803..6333844868 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -882,6 +882,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
--
2.35.2
Samuel Mira
Senior Software Developer
The Qt Company
Tutkijantie 4C
FI-90590 Oulu
Finland
samuel.mira at qt.io<mailto:samuel.mira at qt.io>
www.qt.io<https://www.qt.io>
[signature_3255782021]<https://www.qt.io/>
[signature_3655584933]<https://www.facebook.com/qt/>
[signature_3785140935]<https://twitter.com/qtproject>
[signature_765191051]<https://www.linkedin.com/company/the-qt-company/>
[signature_2165164460]<https://www.youtube.com/QtStudios>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6491 bytes
Desc: image001.png
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 697 bytes
Desc: image002.png
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 875 bytes
Desc: image003.png
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 763 bytes
Desc: image004.png
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 734 bytes
Desc: image005.png
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avcodec-mediacodec-add-vp9-encoder-using-mediacodec.patch.b64
Type: application/octet-stream
Size: 9345 bytes
Desc: 0001-avcodec-mediacodec-add-vp9-encoder-using-mediacodec.patch.b64
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230327/33a3d686/attachment.obj>
More information about the ffmpeg-devel
mailing list