Skip to content
No description or website provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Use 'mc264','mcaac' instead of 'libx264','aac'.

FFmpegMC264 is a ffmpeg android library powered by MediaCodec HW accelated encoder.
Now use 'mc264', 'mcaac' instead of 'libx264','aac' in runing ffmpeg command in your code.

FFmpegMC264 library doesn't call ffmpeg executable file through exec(). Instead this library has embedded the ffmpeg as an API function. So, you can call the ffmpeg like this :

  • int retcode = mLibFFmpegMC264.Run(cmdString);
    • cmdString example :

    • ffmpeg -i INPUT -vcodec mc264 -acodec mcaac -f mp4 OUTPUT

    • ffmpeg -i INPUT -vcodec mc264 -b:v 2.0M -acodec mcaac -b:a 128k -f mp4 OUTPUT

    • ffmpeg -i INPUT -vcodec mc264 -b:v 2.0M -r 30 -g 15 -acodec ac3 -f mp4 OUTPUT

    • ffmpeg -i INPUT -vcodec mc264 -b:v 2.0M -r 30 -g 15 -acodec aac -b:a 64k -f mp4 OUTPUT

      • aac : '-b:a 64k' recommended or AV sync problem on my device (LG Q6).
    • ffmpeg -re -i /sdcard/movie.avi -vcodec mc264 -acodec mcaac -f mpegts udp://

    • ffmpeg -re -i /sdcard/movie.avi -vcodec mc264 -b:v 2.0M -acodec mcaac -b:a 128k -max_muxing_queue_size 400 -f mpegts udp://

      • -max_muxing_queue_size 400 : to avoid muxer queue overflow
    • ffmpeg -i rtsp:// -vcodec mc264 -an -f mpegts udp://

    • ffmpeg -probesize 0.3M -fflags nobuffer -use_wallclock_as_timestamps 1 -i rtsp:// -vcodec mc264 -an -f mpegts udp://

      • -fflags nobuffer -use_wallclock_as_timestamps 1 : to solve AV sync problem
    • generate TV test pattern :

    • ffmpeg -f lavfi -i testsrc -pix_fmt yuv420p -vcodec mc264 -b:v 2.0M -r 30 -g 15 -an -f mp4 OUTPUT

For this, in C side, two encoder modules - mc264.c / mcaac.c - have been added into ffmpeg libavcodec.
In java side, two encoder controller classes - / - have been added over android MediaCodec (H.264 / AAC encoders only).

Enjoy ffmpeg powered by MediaCodec HW accelated encoder.

The APIs you have to know :

prepare an instance

  • mLibFFmpegMC264 = new LibFFmpegMC264();
  • mLibFFmpegMC264.getMC264Encoder().setYUVFrameListener(this, true); - optional API

prepare an AsyncTask

  • ffmpeg_task = new MyTask(this);
  • ffmpeg_task.execute( ffmpegCmdStringArray );

run the instance in the task :: doInBackground()

  • mLibFFmpegMC264.Ready();
  • mLibFFmpegMC264.Run( strings );


  • mLibFFmpegMC264.Stop();
  • mLibFFmpegMC264.ForceStop(); - optional API to enforce stop

post stop

  • mLibFFmpegMC264.Reset();

Supported Color Format :

  • ffmpeg INPUT stream : yuv420p
  • MediaCodec : YV12 [NV12] (MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar)

The INPUT stream should have the color format YUV420Planar. Or use '-pix_fmt yuv420p' option with INPUT.
The MediaCodec of your device should have the color format YV12 [NV12]. (Other formats will be supported later)

Limitations :

  • The running time is limited to 30 minutes. Contact me for the unlimited version of FFmpegMC264 module including source.


Calss Diagram

Referenced Links :

You can’t perform that action at this time.