MPEG-TS, Android and FFMPEG

STeN picture STeN · Feb 15, 2012 · Viewed 7.6k times · Source

I am receiving the MPEG-TS (MPEG transport stream) packets with the multiplexed H.264 video and AAC audio streams. I need to be able to show the audio and video on the Android phone. My assumption is that I need:

  • MPEG-TS de-multiplexer
  • AAC decoder
  • H.264 decoder
  • Synchronize the audio and video playback

Assuming that I am right then (in Android 2.x) MPEG-TS de-multiplexer is not part of the OS and must be ported, both AAC and H.264 decoder are part of the Android OS, but I am not sure if they have interface, which allows passing the data in buffers and if they allow mutual timing synchronization. In the worst case those components must be ported here as well.

Can you give me some advices where to start? I was thinking about the FFMPEG porting. Are there any other ways?

Regards, STeN

Answer

Dmitry picture Dmitry · Aug 19, 2012

Android 4.x has OpenMAX which can play TS with H264 and AAC. You don't even need to worry about synchronisation of audio and video.

Look at the nativemedia sample in the NDK.

If you want to support previous versions of Android, then ffmpeg might be a good choice, but it the maximum it can give you is just decoded video frames in RGB or any other format and decoded audio in PCM. Then you will have to implement renderer and audio playback yourself. I would recommend reading this tutorial - http://dranger.com/ffmpeg/. It is not android specific but it will give you idea how video play works.