Wesley
Wesley

Reputation: 583

How to transcode a video using the MediaCodec api for Android 4.3+

I have been using FFmpeg to do video transcode, it works but its very slow.

I have also tried the Intel Inde library but does not work on some Android phones I have tested.

Therefore I want to make use of the MediaCodec Api to transcode video.

I have read some sample codes from BigFlake, which helps me to gain some concept for the Api. However I still do not know how I can transcode a video file from one format to another.

I do not have experience working with codec, and the flow I think is:

Decode input video file(frame?) -> feed into encoder -> convert the stream to a .MP4 file.

Appreciate if anyone can point me to the right direction.

Upvotes: 2

Views: 2976

Answers (1)

fadden
fadden

Reputation: 52303

You seem to understand the fundamentals already. Your work flow is correct -- feed the output of the decoder to the input of the encoder. If you want the result to be a .mp4 file, send AVC output through MediaMuxer.

The tricky parts have to do with what you're trying to accomplish by transcoding. Changing the size or bit rate of the video is straightforward, as you just need to configure the encoder appropriately. Filtering the video is a bit more complex, as you'll probably want to use OpenGL ES for performance reasons (DecodeEditEncode test on bigflake demonstrates this). Altering the frame rate can get complicated.

For best results do everything through Surface (requires API 18+). This assumes that your video decoder supports output to a Surface; if not, you will likely need to render it yourself.

Some additional MediaCodec examples can be found in Grafika.

Upvotes: 2

Related Questions