[FFmpeg-devel] [PATCH 1/2] avcodec/mediacodec add vp9 encoder using mediacodec
"zhilizhao(赵志立)"
quinkblack at foxmail.com
Tue Mar 28 11:43:42 EEST 2023
> On Mar 27, 2023, at 23:21, Samuel Raposo Vieira Mira <samuel.mira at qt.io> wrote:
>
> 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(+)
This patch set LGTM. There is a warning on the patch subject:
> The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: “.
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=8627
I can fix it before push. Will do more test and apply in this week.
>
> 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>
>
>
> <image001.png><image002.png><image003.png><image004.png><image005.png><0001-avcodec-mediacodec-add-vp9-encoder-using-mediacodec.patch.b64>_______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-devel
mailing list