LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-06-2006, 12:06 PM   #1
cato4liberty
LQ Newbie
 
Registered: Aug 2003
Posts: 9

Rep: Reputation: 0
HOWTO: Convert MPEG2 into MP4


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
 
Old 02-06-2006, 12:08 PM   #2
cato4liberty
LQ Newbie
 
Registered: Aug 2003
Posts: 9

Original Poster
Rep: Reputation: 0
Here are details of the input file (MPEG2) and the output file (MP4).

Details of the input file (MPEG2)
Code:
$ midentify myfile.mpeg
ID_VIDEO_ID=0
ID_AUDIO_ID=0
ID_FILENAME=myfile.mpeg
ID_DEMUXER=mpegps
ID_VIDEO_FORMAT=0x10000002
ID_VIDEO_BITRATE=2662400
ID_VIDEO_WIDTH=480
ID_VIDEO_HEIGHT=480
ID_VIDEO_FPS=29.970
ID_VIDEO_ASPECT=1.3333
ID_AUDIO_CODEC=mp3
ID_AUDIO_FORMAT=80
ID_AUDIO_BITRATE=128000
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
ID_LENGTH=60.17
ID_VIDEO_CODEC=mpegpes
Details of the output file (MP4)
Code:
$ midentify myfile.mp4
ID_VIDEO_ID=0
ID_AUDIO_ID=1
ID_FILENAME=myfile.mp4
ID_DEMUXER=mov
ID_VIDEO_FORMAT=avc1
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=640
ID_VIDEO_HEIGHT=480
ID_VIDEO_FPS=29.969
ID_VIDEO_ASPECT=0.0000
ID_AUDIO_CODEC=faad
ID_AUDIO_FORMAT=mp4a
ID_AUDIO_BITRATE=125424
ID_AUDIO_RATE=48000
ID_AUDIO_NCH=2
ID_LENGTH=60.33
ID_VIDEO_CODEC=ffh264
Details of the output file (MP4) using mp4info
Code:
$ mp4info myfile.mp4
mp4info version 1.4.1
myfile.mp4:
Track   Type    Info
1       video   H264 High @5.1, 60.329 secs, 1002 kbps, 640x480 @ 29.935852 fps
2       audio   MPEG-4 AAC LC, 60.501 secs, 125 kbps, 48000 Hz
 
Old 02-06-2006, 12:09 PM   #3
cato4liberty
LQ Newbie
 
Registered: Aug 2003
Posts: 9

Original Poster
Rep: Reputation: 0
If anyone has suggestions for improvement, please do share your thoughts. I am curious about any options or settings to improve the quality or reduce the conversion time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
howto convert .flac to .mp3 Lleb_KCir Linux - Software 4 05-21-2005 06:07 PM
howto convert .avi to svcd? Brain Drop Linux - Software 3 11-28-2004 09:13 PM
mp4 and k3b mikedeatworld Linux - Software 5 08-14-2004 09:17 PM
Howto convert Gentoo wlan scripts to Debian? Naughtyus Debian 1 02-25-2004 03:55 PM
Convert MPEG2 into xvid alitrix Linux - Software 4 02-18-2004 05:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration