I use the following steps to convert video capture MPEG2 files into MP4 format (H.264 and AAC). Basically, the video will be converted into H.264 using two-pass x264, and the PCM audio will be converted into AAC. The H.264 video and AAC audio will then be muxed into the MP4 container.
In a few test runs I noticed that MP4 took up less than half the space of MPEG2 at a similar quality level.
- MPEG2: 18 MB (640x480 @ 29.9 fps, 2662 kbps video, 128 kbps 48 khz audio)
- MP4: 8.2 MB (640x480 @ 29.9 fps, 1002 kbps video, 125k 48 khz audio)
___________________________________________________________________
Steps to convert MPEG2 into MP4
Demux MPEG2 into M2V and MP2
Code:
mpeg_ps_extract --video --audio myfile.mpeg
Convert video: M2V to x264 - Pass 1
Code:
mencoder -ovc x264 -x264encopts pass=1:\
qcomp=0.75:subq=5:4x4mv:8x8dct:frameref=2:bframes=3:b_pyramid:\
weight_b:log=-1 -ofps 29.97 -vf scale=640:480 -passlogfile \
x264logfile myfile.m2v -of rawvideo -o myfile.264
Convert video: M2V to x264 - Pass 2
Code:
mencoder -ovc x264 -x264encopts pass=2:bitrate=1000:qcomp=0.75:\
subq=5:4x4mv:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b:\
log=-1 -ofps 29.97 -vf scale=640:480 -passlogfile x264logfile \
myfile.m2v -of rawvideo -o myfile.264
Extract audio into PCM WAV
Code:
ffmpeg -v 0 -i myfile.mpeg -vn myfile.wav
Convert audio: PCM WAV to AAC
Code:
faac --mpeg-vers 4 -b 128 -c 44100 myfile.wav -o myfile.aac
Mux into MP4: H.264 video and and AAC audio
Code:
MP4Box -add myfile.264:fps=29.97 -add myfile.aac myfile.mp4