From: Samuel Raposo Vieira Mira <samuel.mira@qt.io> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/mediacodec: add mpeg4 encoder Date: Mon, 27 Mar 2023 15:21:27 +0000 Message-ID: <DBAPR02MB6165762C3E66BDC164E593A3ED8B9@DBAPR02MB6165.eurprd02.prod.outlook.com> (raw) [-- Attachment #1.1: Type: text/plain, Size: 8497 bytes --] This patch will add MPEG4 encoder using Android Mediacodec Signed-off-by: Samuel Mira <samuel.mira@qt.io<mailto:samuel.mira@qt.io>> --- configure | 2 ++ libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/mediacodec_wrapper.c | 55 +++++++++++++++++++++++++++++++++ libavcodec/mediacodecenc.c | 49 +++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) diff --git a/configure b/configure index 101bc7b2f1..be0c201414 100755 --- a/configure +++ b/configure @@ -3226,6 +3226,8 @@ mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m" mpeg4_crystalhd_decoder_select="crystalhd" mpeg4_cuvid_decoder_deps="cuvid" mpeg4_mediacodec_decoder_deps="mediacodec" +mpeg4_mediacodec_encoder_deps="mediacodec" +mpeg4_mediacodec_encoder_extralibs="-landroid" mpeg4_mmal_decoder_deps="mmal" mpeg4_omx_encoder_deps="omx" mpeg4_v4l2m2m_decoder_deps="v4l2_m2m mpeg4_v4l2_m2m" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3d213014c6..77b7c988c5 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -542,6 +542,7 @@ OBJS-$(CONFIG_MPEG4_DECODER) += mpeg4videodsp.o xvididct.o OBJS-$(CONFIG_MPEG4_ENCODER) += mpeg4videoenc.o OBJS-$(CONFIG_MPEG4_CUVID_DECODER) += cuviddec.o OBJS-$(CONFIG_MPEG4_MEDIACODEC_DECODER) += mediacodecdec.o +OBJS-$(CONFIG_MPEG4_MEDIACODEC_ENCODER) += mediacodecenc.o OBJS-$(CONFIG_MPEG4_OMX_ENCODER) += omx.o OBJS-$(CONFIG_MPEG4_V4L2M2M_DECODER) += v4l2_m2m_dec.o OBJS-$(CONFIG_MPEG4_V4L2M2M_ENCODER) += v4l2_m2m_enc.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 6333844868..24fd935211 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -871,6 +871,7 @@ extern const FFCodec ff_mpeg2_qsv_encoder; extern const FFCodec ff_mpeg2_vaapi_encoder; extern const FFCodec ff_mpeg4_cuvid_decoder; extern const FFCodec ff_mpeg4_mediacodec_decoder; +extern const FFCodec ff_mpeg4_mediacodec_encoder; extern const FFCodec ff_mpeg4_omx_encoder; extern const FFCodec ff_mpeg4_v4l2m2m_encoder; extern const FFCodec ff_prores_videotoolbox_encoder; diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index b13211d435..46445bc7d6 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -327,6 +327,23 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx) static const int VP9Profile3HDR = 0x2000; static const int VP9Profile2HDR10Plus = 0x4000; static const int VP9Profile3HDR10Plus = 0x8000; + + static const int MPEG4ProfileSimple = 0x01; + static const int MPEG4ProfileSimpleScalable = 0x02; + static const int MPEG4ProfileCore = 0x04; + static const int MPEG4ProfileMain = 0x08; + static const int MPEG4ProfileNbit = 0x10; + static const int MPEG4ProfileScalableTexture = 0x20; + static const int MPEG4ProfileSimpleFBA = 0x80; + static const int MPEG4ProfileSimpleFace = 0x40; + static const int MPEG4ProfileBasicAnimated = 0x100; + static const int MPEG4ProfileHybrid = 0x200; + static const int MPEG4ProfileAdvancedRealTime = 0x400; + static const int MPEG4ProfileCoreScalable = 0x800; + static const int MPEG4ProfileAdvancedCoding = 0x1000; + static const int MPEG4ProfileAdvancedCore = 0x2000; + static const int MPEG4ProfileAdvancedScalable = 0x4000; + static const int MPEG4ProfileAdvancedSimple = 0x8000; // Unused yet. (void)AVCProfileConstrainedHigh; @@ -381,6 +398,44 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx) case FF_PROFILE_VP9_3: return VP9Profile3; } + } else if(avctx->codec_id == AV_CODEC_ID_MPEG4) { + switch (avctx->profile) + { + case FF_PROFILE_MPEG4_SIMPLE: + return MPEG4ProfileSimple; + case FF_PROFILE_MPEG4_SIMPLE_SCALABLE: + return MPEG4ProfileSimpleScalable; + case FF_PROFILE_MPEG4_CORE: + return MPEG4ProfileCore; + case FF_PROFILE_MPEG4_MAIN: + return MPEG4ProfileMain; + case FF_PROFILE_MPEG4_N_BIT: + return MPEG4ProfileNbit; + case FF_PROFILE_MPEG4_SCALABLE_TEXTURE: + return MPEG4ProfileScalableTexture; + case FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION: + return MPEG4ProfileSimpleFBA; + case FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE: + return MPEG4ProfileBasicAnimated; + case FF_PROFILE_MPEG4_HYBRID: + return MPEG4ProfileHybrid; + case FF_PROFILE_MPEG4_ADVANCED_REAL_TIME: + return MPEG4ProfileAdvancedRealTime; + case FF_PROFILE_MPEG4_CORE_SCALABLE: + return MPEG4ProfileCoreScalable; + case FF_PROFILE_MPEG4_ADVANCED_CODING: + return MPEG4ProfileAdvancedCoding; + case FF_PROFILE_MPEG4_ADVANCED_CORE: + return MPEG4ProfileAdvancedCore; + case FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE: + return MPEG4ProfileAdvancedScalable; + case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: + return MPEG4ProfileAdvancedSimple; + case FF_PROFILE_MPEG4_SIMPLE_STUDIO: + // Studio profiles are not supported by mediacodec. + default: + break; + } } return -1; diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c index c7e2beb1ae..6baa7eda14 100644 --- a/libavcodec/mediacodecenc.c +++ b/libavcodec/mediacodecenc.c @@ -167,6 +167,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) case AV_CODEC_ID_VP9: codec_mime = "video/x-vnd.on2.vp9"; break; + case AV_CODEC_ID_MPEG4: + codec_mime = "video/mp4v-es"; + break; default: av_assert0(0); } @@ -825,3 +828,49 @@ static const AVOption vp9_options[] = { DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9) #endif // CONFIG_VP9_MEDIACODEC_ENCODER + +#if CONFIG_MPEG4_MEDIACODEC_ENCODER + +enum MediaCodecMpeg4Level { + MPEG4Level0 = 0x01, + MPEG4Level0b = 0x02, + MPEG4Level1 = 0x04, + MPEG4Level2 = 0x08, + MPEG4Level3 = 0x10, + MPEG4Level3b = 0x18, + MPEG4Level4 = 0x20, + MPEG4Level4a = 0x40, + MPEG4Level5 = 0x80, + MPEG4Level6 = 0x100, +}; + +static const AVOption mpeg4_options[] = { + COMMON_OPTION + { "level", "Specify tier and level", + OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" }, + { "0", "Level 0", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, "level" }, + { "0b", "Level 0b", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, "level" }, + { "1", "Level 1", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, "level" }, + { "2", "Level 2", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, "level" }, + { "3", "Level 3", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, "level" }, + { "3b", "Level 3b", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, "level" }, + { "4", "Level 4", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, "level" }, + { "4a", "Level 4a", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, "level" }, + { "5", "Level 5", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, "level" }, + { "6", "Level 6", + 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, "level" }, + { NULL, } +}; + +DECLARE_MEDIACODEC_ENCODER(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4) + +#endif // CONFIG_MPEG4_MEDIACODEC_ENCODER -- 2.35.2 Samuel Mira Senior Software Developer The Qt Company Tutkijantie 4C FI-90590 Oulu Finland samuel.mira@qt.io<mailto:samuel.mira@qt.io> www.qt.io<https://www.qt.io> [signature_4074551992]<https://www.qt.io/> [signature_183607293]<https://www.facebook.com/qt/> [signature_465813548]<https://twitter.com/qtproject> [signature_1516411291]<https://www.linkedin.com/company/the-qt-company/> [signature_1076561480]<https://www.youtube.com/QtStudios> [-- Attachment #1.2: image001.png --] [-- Type: image/png, Size: 6491 bytes --] [-- Attachment #1.3: image002.png --] [-- Type: image/png, Size: 697 bytes --] [-- Attachment #1.4: image003.png --] [-- Type: image/png, Size: 875 bytes --] [-- Attachment #1.5: image004.png --] [-- Type: image/png, Size: 763 bytes --] [-- Attachment #1.6: image005.png --] [-- Type: image/png, Size: 734 bytes --] [-- Attachment #2: 0002-avcodec-mediacodec-add-mpeg4-encoder.patch.b64 --] [-- Type: application/octet-stream, Size: 10665 bytes --] [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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".
reply other threads:[~2023-03-27 15:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=DBAPR02MB6165762C3E66BDC164E593A3ED8B9@DBAPR02MB6165.eurprd02.prod.outlook.com \ --to=samuel.mira@qt.io \ --cc=ffmpeg-devel@ffmpeg.org \ /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