PDA

View Full Version : Mp4: Replacing Audio Stream


Zinc
20th January 2007, 18:04
Hi,
I'm very new to the mp4 format, and my question is probably naive, so please bear with me. I have a mp4 encoded file with mp3 audio stream encoded in it. I've also found a AAC audio stream (in a separate .aac file). My question is how can I edit the mp4 file to strip the previous audio stream, and replace it with the AAC stream?

Thanks.

Zero1
20th January 2007, 20:16
If you are familliar with MP4Box, you can do as follows:

Find out the TrackID of the file you want to remove
To do this, simply open a command prompt and type:
mp4box -info "C:\video.mp4"

Obviously you may need to specify the path to MP4Box and the file. This will give you output that looks like this:
...
Track # 1 Info - TrackID 1 - TimeScale 1000000 - Duration 00:05:57.190
Media Info: Language "Japanese" - Type "vide" - Sub Type "avc1" - 5247 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 704 x 480 - Profile High @ Level 4
NAL Unit length bits: 32
Pixel Aspect Ratio 40:33 - Indicated track size 853 x 480
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:05:57.248
Media Info: Language "Japanese" - Type "soun" - Sub Type "mp4a" - 16746 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 48000
Synchronized on stream 1
Here we can see that the audio is in TrackID 2 because it refers to "MPEG-4 Audio AAC LC - 2 Channels(s)". Yours will refer to MPEG-1 Audio, MPEG-1 Layer 3, MP3 or something similar.

Remove the audio track from the MP4
In the same command prompt, simply type this, replacing the # with the TrackID number you found out before, so in this case it would be -rem 2
mp4box -rem # "C:\file.mp4"

Mux the new audio to the MP4
Now still in the command prompt, we will add audio to the file. This is very simple. Just type:
mp4box -add "C:\file.aac" "C:\file.mp4"
Pay attention here, the file you add is the audio (obviously) and the next file in the command line without any switches is the output file. If the output file already exists (in this case it does because it's the video you removed the audio from), it simply adds it to that file so now MP4box adds the AAC to the video only MP4.

If you aren't used to CLI, then YAMB should have similar functions; it should be pretty easy to follow or figure out.

Zinc
21st January 2007, 05:50
Thanks a lot for the detailed instructions.