History

avcodec/mediacodec: add mpeg4 encoder

This patch will add MPEG4 encoder using Android Mediacodec

Samuel Raposo Vieira Mira committed 3 years ago

Commit b4eca5c1 parent 139f3356 files · +109 −1Browse files

Unified · Split

6 files
  1. configure +2 −0
  2. libavcodec/Makefile +1 −0
  3. libavcodec/allcodecs.c +1 −0
  4. libavcodec/mediacodec_wrapper.c +55 −0
  5. libavcodec/mediacodecenc.c +49 −0
  6. libavcodec/version.h +1 −1
configure+2−0
@@ -3228,6 +3228,8 @@ mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m" · 3227 unmodified lines
32283228 mpeg4_crystalhd_decoder_select="crystalhd"
32293229 mpeg4_cuvid_decoder_deps="cuvid"
32303230 mpeg4_mediacodec_decoder_deps="mediacodec"
3231+mpeg4_mediacodec_encoder_deps="mediacodec"
3232+mpeg4_mediacodec_encoder_extralibs="-landroid"
32313233 mpeg4_mmal_decoder_deps="mmal"
32323234 mpeg4_omx_encoder_deps="omx"
32333235 mpeg4_v4l2m2m_decoder_deps="v4l2_m2m mpeg4_v4l2_m2m"
libavcodec/Makefile+1−0
@@ -542,6 +542,7 @@ OBJS-$(CONFIG_MPEG4_DECODER) += mpeg4videodsp.o xvididct.o · 541 unmodified lines
542542 OBJS-$(CONFIG_MPEG4_ENCODER) += mpeg4videoenc.o
543543 OBJS-$(CONFIG_MPEG4_CUVID_DECODER) += cuviddec.o
544544 OBJS-$(CONFIG_MPEG4_MEDIACODEC_DECODER) += mediacodecdec.o
545+OBJS-$(CONFIG_MPEG4_MEDIACODEC_ENCODER) += mediacodecenc.o
545546 OBJS-$(CONFIG_MPEG4_OMX_ENCODER) += omx.o
546547 OBJS-$(CONFIG_MPEG4_V4L2M2M_DECODER) += v4l2_m2m_dec.o
547548 OBJS-$(CONFIG_MPEG4_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
libavcodec/allcodecs.c+1−0
@@ -873,6 +873,7 @@ extern const FFCodec ff_mpeg2_qsv_encoder; · 872 unmodified lines
873873 extern const FFCodec ff_mpeg2_vaapi_encoder;
874874 extern const FFCodec ff_mpeg4_cuvid_decoder;
875875 extern const FFCodec ff_mpeg4_mediacodec_decoder;
876+extern const FFCodec ff_mpeg4_mediacodec_encoder;
876877 extern const FFCodec ff_mpeg4_omx_encoder;
877878 extern const FFCodec ff_mpeg4_v4l2m2m_encoder;
878879 extern const FFCodec ff_prores_videotoolbox_encoder;
libavcodec/mediacodec_wrapper.c+55−0
@@ -328,6 +328,23 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx) · 327 unmodified lines
328328 static const int VP9Profile2HDR10Plus = 0x4000;
329329 static const int VP9Profile3HDR10Plus = 0x8000;
330330
331+ static const int MPEG4ProfileSimple = 0x01;
332+ static const int MPEG4ProfileSimpleScalable = 0x02;
333+ static const int MPEG4ProfileCore = 0x04;
334+ static const int MPEG4ProfileMain = 0x08;
335+ static const int MPEG4ProfileNbit = 0x10;
336+ static const int MPEG4ProfileScalableTexture = 0x20;
337+ static const int MPEG4ProfileSimpleFBA = 0x80;
338+ static const int MPEG4ProfileSimpleFace = 0x40;
339+ static const int MPEG4ProfileBasicAnimated = 0x100;
340+ static const int MPEG4ProfileHybrid = 0x200;
341+ static const int MPEG4ProfileAdvancedRealTime = 0x400;
342+ static const int MPEG4ProfileCoreScalable = 0x800;
343+ static const int MPEG4ProfileAdvancedCoding = 0x1000;
344+ static const int MPEG4ProfileAdvancedCore = 0x2000;
345+ static const int MPEG4ProfileAdvancedScalable = 0x4000;
346+ static const int MPEG4ProfileAdvancedSimple = 0x8000;
347+
331348 // Unused yet.
332349 (void)AVCProfileConstrainedHigh;
333350 (void)HEVCProfileMain10HDR10;
@@ -381,6 +398,44 @@ int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx) · 47 unmodified lines
381398 case FF_PROFILE_VP9_3:
382399 return VP9Profile3;
383400 }
401+ } else if(avctx->codec_id == AV_CODEC_ID_MPEG4) {
402+ switch (avctx->profile)
403+ {
404+ case FF_PROFILE_MPEG4_SIMPLE:
405+ return MPEG4ProfileSimple;
406+ case FF_PROFILE_MPEG4_SIMPLE_SCALABLE:
407+ return MPEG4ProfileSimpleScalable;
408+ case FF_PROFILE_MPEG4_CORE:
409+ return MPEG4ProfileCore;
410+ case FF_PROFILE_MPEG4_MAIN:
411+ return MPEG4ProfileMain;
412+ case FF_PROFILE_MPEG4_N_BIT:
413+ return MPEG4ProfileNbit;
414+ case FF_PROFILE_MPEG4_SCALABLE_TEXTURE:
415+ return MPEG4ProfileScalableTexture;
416+ case FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION:
417+ return MPEG4ProfileSimpleFBA;
418+ case FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE:
419+ return MPEG4ProfileBasicAnimated;
420+ case FF_PROFILE_MPEG4_HYBRID:
421+ return MPEG4ProfileHybrid;
422+ case FF_PROFILE_MPEG4_ADVANCED_REAL_TIME:
423+ return MPEG4ProfileAdvancedRealTime;
424+ case FF_PROFILE_MPEG4_CORE_SCALABLE:
425+ return MPEG4ProfileCoreScalable;
426+ case FF_PROFILE_MPEG4_ADVANCED_CODING:
427+ return MPEG4ProfileAdvancedCoding;
428+ case FF_PROFILE_MPEG4_ADVANCED_CORE:
429+ return MPEG4ProfileAdvancedCore;
430+ case FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE:
431+ return MPEG4ProfileAdvancedScalable;
432+ case FF_PROFILE_MPEG4_ADVANCED_SIMPLE:
433+ return MPEG4ProfileAdvancedSimple;
434+ case FF_PROFILE_MPEG4_SIMPLE_STUDIO:
435+ // Studio profiles are not supported by mediacodec.
436+ default:
437+ break;
438+ }
384439 }
385440
386441 return -1;
libavcodec/mediacodecenc.c+49−0
@@ -167,6 +167,9 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) · 166 unmodified lines
167167 case AV_CODEC_ID_VP9:
168168 codec_mime = "video/x-vnd.on2.vp9";
169169 break;
170+ case AV_CODEC_ID_MPEG4:
171+ codec_mime = "video/mp4v-es";
172+ break;
170173 default:
171174 av_assert0(0);
172175 }
@@ -825,3 +828,49 @@ static const AVOption vp9_options[] = { · 652 unmodified lines
825828 DECLARE_MEDIACODEC_ENCODER(vp9, "VP9", AV_CODEC_ID_VP9)
826829
827830 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
831+
832+#if CONFIG_MPEG4_MEDIACODEC_ENCODER
833+
834+enum MediaCodecMpeg4Level {
835+ MPEG4Level0 = 0x01,
836+ MPEG4Level0b = 0x02,
837+ MPEG4Level1 = 0x04,
838+ MPEG4Level2 = 0x08,
839+ MPEG4Level3 = 0x10,
840+ MPEG4Level3b = 0x18,
841+ MPEG4Level4 = 0x20,
842+ MPEG4Level4a = 0x40,
843+ MPEG4Level5 = 0x80,
844+ MPEG4Level6 = 0x100,
845+};
846+
847+static const AVOption mpeg4_options[] = {
848+ COMMON_OPTION
849+ { "level", "Specify tier and level",
850+ OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
851+ { "0", "Level 0",
852+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, "level" },
853+ { "0b", "Level 0b",
854+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, "level" },
855+ { "1", "Level 1",
856+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, "level" },
857+ { "2", "Level 2",
858+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, "level" },
859+ { "3", "Level 3",
860+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, "level" },
861+ { "3b", "Level 3b",
862+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, "level" },
863+ { "4", "Level 4",
864+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, "level" },
865+ { "4a", "Level 4a",
866+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, "level" },
867+ { "5", "Level 5",
868+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, "level" },
869+ { "6", "Level 6",
870+ 0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, "level" },
871+ { NULL, }
872+};
873+
874+DECLARE_MEDIACODEC_ENCODER(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4)
875+
876+#endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
libavcodec/version.h+1−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929
3030 #include "version_major.h"
3131
32−#define LIBAVCODEC_VERSION_MINOR 8
32+#define LIBAVCODEC_VERSION_MINOR 9
3333 #define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t