These are shell incantations for transcoding video with ffmpeg, especially for the ipod or iphone. ffmpeg is one of several free open source video editing programs you can use. These recipes are here partly to make it easier for other people to find them, and partly for me to find them again.
The standard open-source programs for transforming video are ffmpeg and mencoder. Each is capable from reading video in many different files formats, and writing out video using many different video encoding options. Each is supported in some form on Mac OS X, Linux and probably Windows. Both use common source libraries. You can get ffmpeg at http://www.mplayerhq.hu/design7/dload.html in many forms, or else compiled for Win32 at http://sourceforge.net /project/showfiles.php? group_id=205275.
mencoder has more filters than ffmpeg for processing the video. ffmpeg supports more different input and output formats, including direct output to mp4 container files. mencoder support for non-avi files is new and questionable, so for use with Quicktime you need to post-process with mp4creator: that's too much hassle for me, but instructions can be found at: mplayerhq.
My preferred solution is simply to use ffmpeg.
Basic command for iphone-compatible video
ffmpeg -i input-file -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 480x320 output-file
iphone (better setting than above)
INFILE="$1"
OUTFILE="$2"
ffmpeg -i "$INFILE" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 480x320 -aspect 4:3 "$OUTFILE"
This should be fine with any ipod-like device, but it is customized for
the iPhone screen size.
The -s 480x320 refers to the size of the iPhone screen; customization for the video iPod would use the same incantation, but with a screen size of 320x240 to produce slightly smaller files. On the other hand, showing the video on TV would benefit from the larger size, or even 640x480. The Apple TV uses as much as 1280x720. (It is never worth using a larger size than your input footage, however, which is often limited to 640x480 for NTSC.)
Thus, for the ipod video is might be:
ipod video
ffmpeg -i "$INFILE" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5
-bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 "$OUTFILE"
Other more exotic settings are the following:
sample separate image frames to jpeg images
ffmpeg -i "$INFILE" -y -ss 5 -an -sameq -f image2 -r 1/4 frame%03d.jpg
remove logo(from) from commercial video with lavc mpeg4 codec, avi container
mencoder -vf "delogo=545:401:100:45" -ovc lavc -lavcopts vcodec=mpeg4:acodec=libfaac 002.mpg -o 002.avi
Contrast enhancement (not recommended, can confuse compression)
mencoder -ovc lavc -lavcopts vcodec=mpeg4:acodec=libfaac -vf pp=autolevels:f 002.mpg -o 002.avi
WARNING: note that the -i inputfile flag needs to come early otherwise the resize (resizing/rescaling) flag -s will not have any effect. This is incredibly stupid, yes. At one point I found it didn't work and it took me a long time to figure out the problem that caused my resize to fail.
If you want to play with these, a quick guide to the key (somewhat obscure) ffmpeg parameters are as follows:
`-title string' Set the title. `-b bitrate' Set the video bitrate in bit/s (default = 200 kb/s). `-ss position' Seek to given time position in seconds. hh:mm:ss[.xxx] syntax is also supported. -r fps Set to frame rate `-s size' Set frame size. The format is `wxh' (ffserver default = 160x128, ffmpeg default = same as source). A few of the many allowed appreciations are: `qqvga' 160x120 `qvga' 320x240 `vga' 640x480 `-maxrate bitrate' Set max video bitrate (in bit/s). `-minrate bitrate' Set min video bitrate (in bit/s). `-ar freq' Set the audio sampling frequency (default = 44100 Hz). `-ab bitrate' Set the audio bitrate in bit/s (default = 64k). `-ac channels' Set the number of audio channels (default = 1). `-an' Disable audio recording. `-acodec codec' Force audio codec to codec. Use the copy special value to specify that the raw codec data must be copied as is.