Creating MP4 files - ISO compliant MPEG-4 streams with AAC audio
As you may have heard, 2002 may just be the year where we get standalone players capable of playing DivX videos. In fact, rather ISO compliant MPEG-4 streams as DivX5.x or XviD (and whatever other implementation may come our way.. Apple has Quicktime6 ready but not released it so far). The official audio codec for MPEG-4 is AAC: Advanced Audio Coding. As MPEG-4 video it's heavily patented and essentially you can't get a free encoder. However, as with MP3 and MPEG-4 video there are freely available educational projects for which you usually find some pre-compiled binaries on the net.
The MPEG4IP organization has been working on freely available, cross platform implementation of MPEG-4 tools for quite a while. They have tools to create MP4 streams, encode video to MPEG-4 compliant streams, encode audio to AAC, play back MP4 files and a lot more. Free AAC encoder and decoder implementations can be found on Audiocoding.com. These tools are also open source, however the quality could be better. Currently, the PsyTEL AAC encoder is considered to deliver the best quality.
At this point I would consider the described procedure more as a future outlook of things to come and suggest that only people who are willing to spend (and probably waste) their time trying out new stuff try to create MP4 streams. PsyTEL has an MPEG-4 encoding tool of their own that encodes audio to AAC and video to MPEG-4 ISO and creates an MP4 stream and everything in a nice GUI but as far as I can tell it may also not be freely distributed so it won't be discussed here. It is to be assumed that once MPEG-4 capable hardware devices showing up the selection of encoding tools will grow larger. And if you've been into Ogg Media Streams from the very beginning you may know that it doesn't take much for a format to really take off.. when I wrote the first ogm guide splitting was a pain, editing impossible and multichannel was also not supported and look where we are now.
You will need the following software for this guide:
PsyTEL AACEnc
AACMachine,
BeSweet and BeSplit
MPEG4IP tools
MPEG4IP mp4 player
Please note that the MPEG4IP tools are independent compilations and have not been released by the MPEG4IP. These binaries are for educational use only.
Step 0: Installation
Just a quick note.. put BeSweet and AACMachine into the same directory.
Step 1: Encode video
First you have to create an soundless AVI file. I've tested XviD but DivX4 and DivX3 should also be possible, though changes that the latter can eventually be played on standalones is slim so my suggestion is to stick to the ISO compliant codecs. Just follow the XviD guide and come back here after step3. Also, don't do any audio encoding in GKnot and don't forget to set the FourCC code to DIVX rather than XviD or mp4creator won't accept the input file. DivX5 seems not to be supported at the moment, if I remember correctly there's no proper B frame support in mp4creator yet.
Step 2: Encode the audio
AACMachine allows direct AC3 to AAC transcoding and even supports 5.1ch AACs so why would you want to use anything else for the task?
Step 3: Multiplexing
So far we only have a commandline tool for this operation. The actual program is called mp4creator (mp4creator60.exe). Go to a command-prompt (Start - Run - Command(Win9x/ME) or cmd (WinNT, W2K & WinXP)) and type m4creator60 to get a list of options.
I suggest you put the creator and all the input files at the same place so your commandlines will be shorter. First let's put the video into an MP4 stream:
mp4creator60 -c=ap2.avi -rate=23.976 temp.mp4
will put the video file ap2.avi, having a framerate of 23.976fps into a file called temp.mp4. Then add the audio stream:
mp4creator60 -c=audio.aac -I -rate=23.976 temp.mp4
Then temp.mp4 file will now contain buth audio and video track.
Step 4: Playback
Start up WMP4Player (no relation to Windows Media Player whatsoever) and load your MP4 stream and you're all set. Basic playback operations are there and I'm sure we'll see more advanced players in the future. I tried to play my MP4 stream in DivX Player 2.0alpha 3 but it wouldn't accept it.
Parting words
Will these mp4 streams eventually be playable on a standalone device? They should, as the MPEG4IP implementation is pretty much the reference implementation of these tools, but only time will tell. Also, there are no editing (cutting, etc.) utilities at the moment so you'll have to find an appropriate cut point for audio and video on your own prior to multiplexing. It is also possible creating AVIs containing AAC audio using a DirectShow filter available on the rarewares page, however, the filter is all but problem-free and it's not really worth wasting your time trying it, it takes a lot of tweaking to get it to work properly. When there's a better filter I'll come back to this matter again.
Last but not least I got some crucial info on this procedure from the following pages: http://www.wsu.edu/~benp/trailers.htm, Hydrogenaudio and my forum. Thanks also to everwicked who provided the compiled binaries of the MPEG4IP utilities that can be found on rarewares.
This document was last updated on 09/07/02