Present Location: News >> Blog >> MP4

Blog

> MP4
Posted by prox, from Charlotte, on January 31, 2010 at 22:38 local (server) time

I hate it.

Here's my dilemma:

A few weeks ago my parents sent me their old camcorder with a dozen tapes of ancient home videos.  After playing with my video capture card (DViCO FusionHDTV5 RT Gold - using the composite input) and MEncoder, I finally got a step-by-step process down for each of the tapes.  It went like this:

Press play on camcorder and then immediately execute the following command:

sudo nice -n -10 mencoder -ovc lavc -lavcopts vcodec=ffv1 -oac mp3lame -lameopts cbr:br=224:mode=3 -o raw.avi -tv input=1:normid=0 tv://1

The above encodes to ffv1 (lossless codec) the video coming in from the composite input of my capture card.  The nice command tells it to run at a bit higher priority than normal - mostly because I want to keep using my workstation when this is recording, but not have any user processes (yeah, Flash video) take away from the encoding process.

Next, I do the following to do a two-pass encode of the video with H.264 while keeping the audio intact (we converted to MP3 in the previous step):

mencoder -ovc x264 -vf pp=lb/ha/va/dr,hqdn3d -x264encopts pass=1:bitrate=3000 -oac copy -o /dev/null raw.avi
mencoder -ovc x264 -vf pp=lb/ha/va/dr,hqdn3d -x264encopts pass=2:bitrate=3000 -oac copy -o 1996.avi raw.avi

The pp=lb/ha/va/dr,hqdn3d does some magic by deinterlacing the video and making it look nice.  The output is an AVI container with an H.264 video track and an MP3 audio track.

So far, so good, right?  I did that for all twelve videos, and now am running into a roadblock.

I want to convert all of those to MP4, so QuickTime (yes, my parents have an iMac) can play it.  MEncoder doesn't support MP4 directly, so I have to do an offline conversion.  Normally, I'd just do the following with FFmpeg:

ffmpeg -i 1996.avi -f mp4 -vcodec copy -acodec copy 1996.mp4

MPlayer will play this fine (well, not fine - when seeking, MPlayer can't find keyframes, so starts with a whole bunch of crap on the screen, but this gets better once a keyframe is encountered), but.. QuickTime hates it.  The video stutters horribly, for some reason.

So, I try Avidemux, a video editor I use for a number of other things and normally works very well.  Unfortunately, the MP4 it created doesn't even open in QuickTime!  Turns out this is a known issue.  Avidemux is apparently creating a textbook MP4, but somehow QuickTime didn't read the textbook.  Fail.

I search around a little bit more, and stumble across MP4Box (part of the gpac package in Debian provided by the Debian Multimedia repository).  It required me to split the AVI into its tracks, and then use those to encode, while specifying the framerate (which made sense, since the FPS is in the container):

MP4Box -aviraw video 1996.avi
MP4Box -aviraw audio 1996.avi
MP4Box -fps 29.970 -add 1996_audio.mp3 -add 1996_video.h264 1996.mp4

This doesn't work right, for some reason.  MP4Box doesn't listen to the FPS I'm giving it, and defaults to 25!  Audio and video become desynchronized and it all goes downhill.  I tried -add 1996_video.h264:fps=29.97, too, not really understanding the command-line arguments, but that didn't do anything, either.  I suspect a bug, but I'm not going to bother with that.

I searched around a little more, and I found a Windows utility called MP4Creator that looked like it might be able to do the trick.  I got mixed results, mostly because each time I ran it, I got a different file size!  I also didn't know how to add two tracks, but apparently if you run it twice, it re-interlaves the second track into the existing MP4 (strange).  Here's what I did:

mp4creator -rate=29.97 -c 1996_video.h264 1996.mp4
mp4creator -c 1996_audio.mp3 1996.mp4

Well, this plays perfectly with MPlayer (no problems with seeking!) but, now, we're back to the file not even opening with QuickTime.

What is going on, here?  Is there something else I should be using?  Re-encoding is not an option (and it shouldn't need to be - I have the raw H.264 and MP3 files, and I know the framerate) at this point.

> Add Comment

New comments are currently disabled for this entry.