MP4 media file container with H.264 video and AAC audio

After all audio processing module has been full supported, I migrated the webrtc version to the latest version(update date: 5/9, 2013, svn code: 3988), I got a new assignment today, that is implement mp4 file container for the SDK.

During the discussion of the assignment, I offered my suggestion for the implementation solution, that was import ffmpeg for the SDK, because I was dealing with ffmpeg for over 8 years. By using ffmpeg, it really helps a lot in programming multimedia softwares, codec, container, scaling, streaming, so something else likewise.

However, I got a No, because “ffmpeg is too big for us”. True, this is something we shall concern.

So I can but only turn to mpeg4-ip/mp4v2.

And one more issue must be mentioned here is, the major audio codec of the SDK is G.722.1c. This means if we are intending to have a standard media file container for the SDK, transcode for the audio is required, otherwise, this version of MP4 container can support Windows only, and even more we need to add a DirectX filter for running on Windows.

Mission launched.


FAAC source code: or

AAC implementation in libstagefright of android:

libmp4v2 source code:

Directly to to codes

I must say some of the codes I got from my employer are getting really ugly:

  • No interface & variants comments
  • No sample programs
  • I can have only part of the source code.

So I digged into it myself for the first round of code study, trying to understand what these bouches of codes do, and how they work.

Current status in the previous two days

There are lots of stories during the code study, and after one-full-day’s try and try, I finally managed to write a simple program to run it up, but I still not sure whether it’s the right interfaces and right sequences I’m calling to run it up among the dozens of exported interfaces.

And when I trying to add libmp4v2 to it, I found an even big issue here which may turn the solution down:

We are using mono audio(encoded to G.722 1c) in our products, however, when I transcoded them to AAC and recorded to a MP4 container together with H.264 video, there will be a tremendous noise in the  audio.

I don’t know the exact reason.

So I did some test for it, writing a test program to record stereo audio to Mp4 by using libfaac & libmp4v2, everything works just fine.


Can someone tell me?

One suspecious phenomenon is the audio encoded by the FAAC always been showed as stereo when playing with VLC, whatever the audio format you inputed to FAAC, mono or stereo.

Code segment of encoding mono PCM audio to AAC

hEncoder = faacEncOpen(32000, 1,&samplesInput, &maxBytesOutput);


Next step ( alternative solution for the problem )

After discussed with my supervisor, we decided to  not transcode the audio to AAC, but G.711 , for a temporary solution, but this means:

1. The audio quality will be poorer.

2. But loading for recording a MP4 media file container will be reduced.

I will do this in the next week.

Leave a comment

Your email address will not be published. Required fields are marked *