Converting Digicam Video

Mon, Dec 12, 2005

For serious portraits or low light situations, we've been taking lots of pictures of Annie with my Canon 20D.  I also have a Canon SD300 for convience and video.  The video modes on these small cameras are amazing!  I can't see myself needing more than a couple minutes of video.  Who needs a video camera for their kids these days?

However, dealing with the video out of these things can be tricky.  I post my pictures to smugmug.com (if you sign up use my referrer coupon: aoVCSFuPXSipF).  I've got a plan that also lets me upload videos.  The only format they take is MPEG 1 (for compat reasons) but the camera produces MJpeg AVI files.  Converting these things can be trickier than you'd think. 

Here is what I've ended up doing -- if someone else has a better solution let me know.

  1. Download 'MPlayer-mingw32-1.0pre7.zip' from here [7.8M]. There are a lot of distributions out there but most of the older ones don't work for some reason.  This one at least does something reasonable.
  2. Unzip this into a directory.  I put it under an MPlayer dir in my "program files" dir.
  3. Create a batch file with this in it (call it convert-avi.cmd or something):
    @echo off
    setlocal
    
    set CL="c:\Program Files\MPlayer\mencoder"
    set CL=%CL% -oac lavc -ovc lavc -of mpeg -mpegopts format=mpeg1
    set CL=%CL% -af lavcresample=44100 -vf hqdn3d,harddup -srate 44100
    set CL=%CL% -lavcopts vcodec=mpeg1video:keyint=15:vrc_buf_size=1000
    set CL=%CL%:vrc_maxrate=2500:vbitrate=2500:trell:mbd=2:vrc_init_cplx=1000 
    set CL=%CL% -ni -nobps 
    set CL=%CL% -o %~n1.mpg %1
    %CL%
  4. Call your brand new batch file with the .avi file you need to convert.  It will create a file in the current directory with the same name but a .mpg extension.

This command line is totally out of control.  I couldn't find a way to wrap lines in batch files so I did the environment variable trick.  I got this via trail and error and I'm not sure what all of the options mean, but here is what I know it does:

  • Encodes as MPEG 1 into a .mpg file
  • Upconverts the audio to 44.1 kHz as that is the only freq I could get to work.
  • Doesn't do any resizing or framerate changes (leaves it at 640x480x30fps for my files)
  • Uses a fairly high bitrate to make sure the quality stays good

For a 18.5 second video doing this compression (just to MPEG1 -- let alone something better) cut a 35M AVI file down to 5.5M.  The only problem I haven't figured out is that the first frame is really pixelated.  If you can figure it out you win my undying gratitude.  Check out the docs here or here.

Bonus: You can rotate the video during the conversion with a ,rotate=90 on the after harddup on the -vf argument.

Finally, check out a cute video of Annie here.