Video conversion cheat sheet
I was faffing around with batched video conversion at work today, trying to recall how to get the powerful yet forboding interfaces of MEncoder and ImageMagick to play ball. I've used them both quite extensively before - most recently when encoding in-game footage from Millennium 3. As a younger hacker, I could remember arcane command line options forever, but these days it's a frustrating cycle of never using these tools quite often enough for the syntax to really stick. Such are the ravages of maturity on the capacity to learn!
Anyway, having wasted a load of time today scouring through 1,000KB man pages, I figured I'd jot down the command lines that did what I wanted, and publish them here for future reference. In my experience, what you want is an example of a use case that's vaguely similar to what you want to do, and then you can go look up individual options in the documentation and tweak things to fit your needs.
I'll expand this page as I find new examples. If you have any to share, or if I've said something blatantly wrong, post in the box below.
Open foo.png, resize to 640x480 ignoring aspect ratio, save to foo.jpg with JPEG quality 60.
The ! (ignore aspect ratio) may need to be escaped in some shells (e.g. \!).
convert -resize 640x480! -quality 60 foo.png foo.jpg
Extract audio track from foo.avi, resample to 32KHz, output to foo.wav.
-ni means force non-interleaved mode, useful for reading badly interleaved files correctly.
mplayer -ni -vc null -vo null -af resample=32000 -ao pcm:file=foo.wav foo.avi
Output frames of foo.avi to BMPs named foo_00001.bmp, foo_00002.bmp, etc.
The % needs to be escaped if you're inside a Windows batch file, i.e. foo_%%05d.bmp.
ffmpeg infers the output format from the filename. For JPEG, though, I couldn't find a way to control the compression level (quality), so I output to BMPs and then converted those to JPEG with Imagemagick's "convert".
ffmpeg -i foo.avi -f image2 foo_%05d.bmp
This outputs frames of foo.avi to JPEG files. Each frame is scaled to 640x480 and saved in directory foo_frames with JPEG quality 80.
-noframedrop stops MPlayer from trying to do the conversion in realtime. Without this option, it drops frames, and you end up with fewer JPEGs than you expected.
-noframedrop wasn't included in the MPlayer man page's huge list of command line options, but was sneakily mentioned in a usage example at the end.
mplayer -ni -noframedrop -vo jpeg:quality=80:outdir=foo_frames -vf scale=640:480 foo.avi
This creates a video foo.avi from all the JPEGs in the current directory, with foo.wav as the audio track.
Video format is MS MPEG4 v2 (a good lowest common denominator format for Windows XP/Vista systems) at 25fps. The audio track is encoded to MP3 format using LAME.
mencoder -audiofile foo.wav mf://*.jpg -ovc lavc -lavcopts vcodec=msmpeg4v2 -mf fps=25 -oac mp3lame -o foo.avi
For each foo.avi in the current directory, extract the audio track to foo.wav.
FOR %%i IN (*.avi) DO CALL :encode "%%i" "%%~ni.wav"
mplayer -ni -noframedrop -vc null -vo null -ao pcm:fast:file=%2 %1
For each foo.avi in the current directory, make a new movie with_new_audio/foo.avi, with a video track copied from foo.avi, and a PCM audio track from foo.wav.
FOR %%i IN (*.avi) DO CALL :encode %%i
mencoder -ovc copy -oac pcm -audiofile "%~n1.wav" -o with_new_audio/%1 %1
Finally, I always end up needing a list of the codecs available via mencoder -ovc lavc -lavcopts vcodec:codec_name. So here are the possible values for codec_name:
mjpeg, ljpeg, h261, h263, h263p, mpeg4, msmpeg4, msmpeg4v2, wmv1, wmv2, rv10, mpeg1video, mpeg2video, huffyuv, ffvhuff, asv1, asv2, ffv1, flv, dvvideo, svq1, snow
Post a comment
Powered by clunkyblog release 3.10. Generated in 10ms.