How to encode Quicktime compatible H.264/MPEG-4 AVC within mencoder
0. IntroductionIn this Article I want to show you the proper command options for mencoder to encode high quality H.264 videos which are also playable by the Quicktime video player. I am using it to encode videos in Linux however the commands could be also ported to windows.
I have already posted a blog about encoding image sequence into the new H.264 Codec within ffmpeg, mencoder and some other tools. The previous post was in germain language. If you want to read it then click here. However the command lines posted before produce video files which can not be played by Quicktime.
1. Encoding audioFirst you have to encode the sound track which will be muxed later with raw video data. For better support throughout all available video players you have to encode your audio track in some format suitable for H.264 conformed video streams. My choose is AAC codec because it is supported by most of the players and it seems to be one of the prefered audio codec for the H.264/MPEG4-AVC videos.
Grab your current soundtrack into a PCM wave format. This would create a file audiodump.wav in the current directory
mplayer -ao pcm -vc null -vo null INPUT.avi
Now perfrom audio conversion within faac-command. Faac is an AAC encoder which can be found on Faac-Sourceforge
faac -q 100 -c 44100 -b 192 --mpeg-vers 4 audiodump.wav
This command will encode audiodump.wav to a MPEG4-AAC confirm file audiodump.aac. With the options -b you define the bitrate in this case 192kb
2. Encoding videoThe command below is used to encode a png image sequence into a raw h264 video stream which is compatible to Quicktime 7. To encode other input files like videos in other format you have to replace "mf://PATH/*.png -mf fps=FPS" by "input.avi" for example.
Please replace PATH, FPS and BITRATE with your values
mencoder mf://PATH/*.png -mf fps=FPS -vf scale=720x576,harddup -ovc x264 -x264encopts bitrate=BITRATE:threads=auto:frameref=5:bframes=0:nob_pyramid:nob_adapt:direct_pred=auto:subq=6:mixed_refs:nodct_decimate:no_psnr -nosound -ofps FPS -noskip -of rawvideo -o output.264For 2-Pass encoding do following:
mencoder mf://PATH/*.png -mf fps=FPS -vf scale=720x576,harddup -ovc x264 -x264encopts pass=1:bitrate=BITRATE:threads=auto:frameref=5:bframes=0:nob_pyramid:nob_adapt:direct_pred=auto:subq=6:mixed_refs:nodct_decimate:no_psnr -nosound -ofps FPS -noskip -of rawvideo -o /dev/null
mencoder mf://PATH/*.png -mf fps=FPS -vf scale=720x576,harddup -ovc x264 -x264encopts pass=2:bitrate=BITRATE:threads=auto:frameref=5:bframes=0:nob_pyramid:nob_adapt:direct_pred=auto:subq=6:mixed_refs:nodct_decimate:no_psnr -nosound -ofps FPS -noskip -of rawvideo -o output.264
Mencoder will create a file output.264, which contains a raw h264 video stream. Perform step 3 to mux it with the audio track.
3. Muxing audio + video to mp4To combine audio and video tracks together I am using MP4BOX, which is a part of gpac-package.
Replace FPS with the frame per second as already defined above.
MP4Box -fps FPS -add output.264 -add audiodump.aac output.mp4
After mp4box finishes his work there will be a file output.mp4 containing a video track encoded with H.264/MPEG-4 AVC and an audio track encoded with AAC. You can now delete all temporary files (audiodump.wav, audiodump.aac, output.264)
4. Compatibility and QualityI have encoded an image sequence of about 7500 png files. The quality is better then previous MPEG4 or MPEG2 encodings by even smaller bitrate. The video files are playable in MPlayer, VLC and Xine. Windows Media Player can also play them but require codec installation first. And finally Quicktime 7 and above can also play such video files. I am not sure if a Quicktime player on Mac is able to decode them.
Art Tevs, 11. May 2007 22:05:29.
Der Artikel wurde 147664 mal aufgerufen.