View Full Version : HowTo mux AVC into MP4 with MP4Box
bond
11th April 2005, 15:28
as some might have already realised mp4box from the gpac project is now also able to mux avc into .mp4, here is a small guide for how to do it:
first of all mp4box only handles raw avc streams (normally with the .264 or .h264 extension) or avc already placed in .mp4 as input
if you have avc in avi you can extract it with the avi2raw tool from mpeg4ip (http://www.aziendeassociate.it/cd.asp?dir=/mpeg4iptools) via the commandline
avi2raw -v input.avi output.264for demuxing avc from .mpg there are various tools (eg ffmpeg and videolan) but i always use mplayer (http://www.aziendeassociate.it/cd.asp?dir=/mplayer) (for no special reason):
mplayer -dumpvideo -dumpfile output.264 input.mpg
ok now for muxing the raw avc stream into mp4 with mp4box we simply need the following commandline:
MP4Box -add input.264 -fps X output.mp4 -fps tells what framerate the stream should get (eg 30), by default mp4box uses 25 fps
if you add additional -add commands you can also add other streams, eg an audio stream with the same commandline (-add audio.mp4)
latest mp4box can be get here (http://4nykey.nm.ru/misc/gpac.7z), right click -> save as (thx to opsis81)
easy, right? ;)
Doom9
11th April 2005, 15:29
you might want to update that link because it's not working anymore ;)
bond
11th April 2005, 15:33
btw you need an uptodate ffdshow compile for playing these .mp4 files (if you want to use ffdshow), the latest ones publically available (eg from milans or celtic_druids page) still have a bug milan fixed some days ago
of course other players work correctly
Originally posted by Doom9
you might want to update that link because it's not working anymore ;) just added that you need a "right click -> save as" ;)
yaz
11th April 2005, 15:36
i've just scanned the gpac 'author' page and found :
Media track Extraction
...
-aviraw track : extracts avi track to its native format. track can be one of video, audio, audioN N being the number of the audio track.maybe, we don't need avi2raw anymore ;)
the bests
y
bond
11th April 2005, 16:09
Originally posted by yaz
i've just scanned the gpac 'author' page and found :
maybe, we don't need avi2raw anymorecool works indeed :)
of course, beaware when exporting a packed bitstream avi to raw with this (or avi2raw) you will not get a really correct raw video stream (as it will be full of dummy n-vops)
FoxMan
12th April 2005, 08:43
I've found this bit out this weekend while trying to create my first mp4 file :).
Perhaps these kind of things could be thrown in a sticky. And maybe some things from the "Import chapters into mp4"-post can be added aswell, it might make things easier for people trying to make mp4-files.
Doom9
12th April 2005, 09:40
as it will be full of dummy n-vopsI'm just curious.. would it not be possible to detect and get rid of those during the extraction process? I mean.. mpeg4modifier can detect if its packed bitstream or not, so knowing that it should be possible to remove it properly, should it not? iirc mpeg4modifier can even unpack a packed bitstream AVI.
yaz
12th April 2005, 13:12
hmmm ... time ago it was told on the same 'author' page
MP4Box -import file.avi dest.mp4 : converts avi into MP4 and handles B-Frame correct import (packed bitstreams, n-Vops)this sentence is not there anymore but it seems(seemed) to me that gpac is (at least) beware of the problem. would 'correct' mean here packing a lot of n-vops ???
the bests
y
bond
12th April 2005, 17:15
Originally posted by Doom9
I'm just curious.. would it not be possible to detect and get rid of those during the extraction process? I mean.. mpeg4modifier can detect if its packed bitstream or not, so knowing that it should be possible to remove it properly, should it not? iirc mpeg4modifier can even unpack a packed bitstream AVI. well the aviextract option of mp4box simply extracts what is there in the avi. if the content in the avi is crap, the codec, which writes this crap, should fix that ;)
mp4box is able to remove all the packed bitstream quirks while importing (unpacking, remove dummy n-vops, change userdata to not signal packed bitstream anymore) from avi and raw
Doom9
12th April 2005, 18:43
so in other word, the -aviraw function lacks in sophistication, but that code is already present in the -import.. I guess a code synch wouldn't hurt. Reminds me to get some of my own MeGUI code in synch ;)
FoxMan
12th April 2005, 19:51
Getting back on the first post in this topic. Aren't you supposed to use #video and #audio for the first audio and video track? Like this:
mp4box -add video.264#video -add audio.mp4#audio mp4File.mp4
bond
12th April 2005, 22:47
Originally posted by FoxMan
Getting back on the first post in this topic. Aren't you supposed to use #video and #audio for the first audio and video track? Like this:
mp4box -add video.264#video -add audio.mp4#audio mp4File.mp4no, i think the docs are pretty clear about that:
#audio/#video can be used on .avi and .mpg import files to tell mp4box to only take the audio or video stream from the input, if more than 1 streams are in the input
on mp4 files you have to use #trackid with the trackid of the track you want to import in such a case
of course for importing raw streams and files with only one stream in them this switch doesnt make any sense
Originally posted by Doom9
so in other word, the -aviraw function lacks in sophistication, but that code is already present in the -import.. I guess a code synch wouldn't hurt.i prefer jeanlf not to waste too much time on writing workarounds for crappy codecs, if they cant manage to write normal streams its not mp4box which lacks sophistication imho ;)
FoxMan
13th April 2005, 08:24
Originally posted by bond
no, i think the docs are pretty clear about that:
#audio/#video can be used on .avi and .mpg import files to tell mp4box to only take the audio or video stream from the input, if more than 1 streams are in the input
on mp4 files you have to use #trackid with the trackid of the track you want to import in such a case
of course for importing raw streams and files with only one stream in them this switch doesnt make any sense
Ok, my bad. I haven't read the documents on gpac.sf.net good enough. I thought you could specify the default audio and video tracks with this.
Great Dragon
14th April 2005, 14:57
Imported HE-AAC by MP4Box is detected by CoreAAC as AAC+SBC-type, and not as AAC LC with twice bigger bitrate. IMHO this is much better than using mp4iptools importing.
Doom9
14th April 2005, 21:05
i prefer jeanlf not to waste too much time on writing workarounds for crappy codecs, if they cant manage to write normal streams its not mp4box which lacks sophistication imhoWell.. you'd be surprised how many times you can re-use code and in the end that makes your program simpler.. refactoring, while time consuming, should turn out better code in the end.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.