[MEncoder-users] Remuxing to mp4 on windows

James Hastings-Trew jimht at shaw.ca
Fri May 9 04:14:55 CEST 2008


Raimund Berger wrote:
> So demuxing should be done differently, and apparently MP4Box itself can
> deal with the avi's created by mplayer pretty well. What I usually do is
>
>  MP4Box -aviraw video clip.avi
>  MP4Box -aviraw audio clip.avi
>
> which produces raw AAC/AVC stream files "clip_audio.raw" and
> "clip_video.h264". Then I rename the audio file to "clip_audio.aac"
> and mux with MP4Box
>
>  MP4Box -add clip_video.h264 -add clip_audio.aac clip.mp4
>
> That works on Linux at least, and I'm pretty confident it will work on
> Windows either.
In my testing I found that while the video file produced by this method 
is valid, the audio file is not. I had success with encoding the audio 
to pcm format, and using mplayer to extract that to a .wav file, and 
then using neroAacEnc to encode that to suitable aac file that mp4box 
was happy with. I used my own x264 encoding options - perhaps someone 
here can suggest better/smarter ones. I tend to stick with what plays 
back smoothly in Quicktime player. Note also that my source video for 
this example was 23.976 fps - important to know when muxing into the MP4 
with mp4box if your framerate is anything other than 25fps.

encode.bat
===============================================================
@echo off
rem step 1 encode the video and convert the audio to 2 channel stereo

rem video pass 1
mencoder %1 -o NUL -vf harddup -oac copy -ovc x264 -x264encopts 
bitrate=5000:vbv_maxrate=8000:vbv_bufsize=1835:bframes=3:nocabac:frameref=1:subq=1:level_idc=31:threads=3:pass=1:turbo

rem video and audio pass 2
mencoder %1 -o temp.avi -of avi -vf harddup -oac pcm -channels 2 -srate 
48000 -ovc x264 -x264encopts 
bitrate=5000:vbv_maxrate=8000:vbv_bufsize=1835:bframes=3:partitions=all:me=umh:nocabac:frameref=6:subq=6:level_idc=31:threads=3:pass=2

rem step 2 extract the raw video
mp4box -aviraw video temp.avi

rem step 3 extract the audio to a wav file
mplayer temp.avi -vc null -vo null -ao pcm:fast

rem step 4 delete the intermediate avi file as it is no longer needed
del temp.avi >NUL

rem step 5 normalize the audio
normalize audiodump.wav

rem step 6 encode the audio to aac
neroaacenc -lc -br 160000 -if audiodump.wav -of temp.m4a

rem step 7 delete the intermediate audio file as it is no longer needed
del audiodump.wav >NUL

rem step 8 mux the video and audio together into an mp4 container
del %2.mp4 >NUL
mp4box -add temp_video.h264 -add temp.m4a -fps 23.976 -tmp c:\temp %2.mp4

rem step 9 cleanup
del temp_video.h264 >NUL
del temp.m4a >NUL
del divx2pass.log >NUL
===============================================================

Hope this helps.



More information about the MEncoder-users mailing list