Head to the labs – it’s time to mix up some videos. Photo (CC-BY) Horia Varlan.

ffmpeg is the industrial-strength, fully free, fully open-source, fully cross-platform do-everything video library for Mac, Windows, and Linux. We’ve seen some basic recipes for splitting video and audio. We’ve covered how to use it on Windows.

But via comments, here’s more ffmpeg goodness than you can possibly handle. It reveals that ffmpeg’s GUI-less, bare-bones command line is an asset, not a liability. Type one line, accomplish anything, get your work done. ffmpeg may be our last, best hope to make sense of a chaotic video world.

Troy Strum is our hero; he’s actually agreed to share his favorite gems assembled on his company wiki.

Have a look, convert in health, and enjoy. And if you wind up making your own variant of one of the below, let us know.

Troy’s ffmpeg Recipe Book

Calculate MPEG4 (or similar) Bitrate:

Where the values for W, H and FPS are the values you’re using for the destination video file.

Where QUALITY is from 0.15 to 0.20 to 0.25 (aprox: low, medium, high)

Slideshows and other still material can use a much lower bitrate.

(W * H * FPS * QUALITY) / 1000 = VIDEO_BITRATE

Note: Use common sense. If it looks like crap, increase the bitrate or change the options! See the note on using “qscale” istead of bitrate in FFMPEG!

Automatically Set Bitrate in FFMPEG:

“The available qscale values range from 1 (highest quality) to 31 (lowest quality). Going worse than a 13 qscale produces unacceptably poor quality”

The “q” is also shown during encoding. If you see a lot of “q=1” you’re not using enough compression. If you see lots of “q” values over 13, you may be using too much.

Use -qscale to set the (variable) bitrate. Try -qscale 4 or -qscale 5

The “-b” bitrate switch has no effect with “-qscale”. It will default to 200kbit and show 200kbit, but actual bitrates will be adjusted to match the q value!

http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/

Convert a (short) DVD into an MOV file

In this case, the whole video is contained in VTS_01_1.VOB

For longer stuff split across VOBs, this won’t work!

Linux or Windows version of FFMPEG

Example shows Windows paths.

We use this to make MOVs from DVDs.
ffmpeg.exe -i E:VIDEO_TSVTS_01_1.VOB -s 640×480 -acodec libmp3lame -b 800k output.mov

Convert any video file into a DV stream

Windows or Linux
something.avi could be anything FFMPEG can read – MOV, MPG, AVI, etc.
ffmpeg -i something.avi -target ntsc-dv output.dv

Convert any video file into a DVD VOB stream

Windows or Linux
something.avi could be anything FFMPEG can read – MOV, MPG, AVI, etc.
ffmpeg -i something.avi -target ntsc-dvd output.vob

Convert a file’s Container without Reencoding

Example shows encapsulating a DV stream into a QuickTime MOV container.

Warning: Just because FFMPEG can do it doesn’t mean a given program will play it!
ffmpeg -i something.dv -acodec copy -vcodec copy output.mov

Extracting a frame as a JPEG:
ffmpeg -i input.flv -vcodec mjpeg -vframes 1 -an -f rawvideo -y -ss 5 output.jpg
“-ss 5” means “grab the frame 5 seconds into the video”

Adding…
-s 64×32 -padtop 8 -padbottom 8
…allows you to scale the JPEG, and in this case makes a 4:3 letterboxed thumbnail image from a 16:9 video at 64×48 pixels.

Output all frames of a given video to a sequence of JPEG images:

ffmpeg -i input.mkv -an output%d.jpg

You can scale these with the -s parameter, like “-s 640×480”

Convert a video to flash video for the web:

ffmpeg -y -i input.dv -ar 22050 -ab 56k -aspect 4:3 -b 2000kb -g 30 -r 30 -f flv -s 640×480 -acodec libmp3lame -ac 1 output.flv

640×460 @ 30fps @ 2000kbit with mono MP3 audio @ 56kbit @ 22050 Hz.

(Some of my other notes talk about using the qscale value in ffmpeg rather than specifying a video bitrate, which could be used here as well.)

“Automatic” Conversion

One of the great things about ffmpeg is that it’s pretty damn good at figuring out what you want it to do just by looking at the input and output file extensions. So just doing:

ffmpeg -i input.mkv output.avi

…is likely to at least give you something! From there you can start adding to the command line to get exactly what you need.

In some cases ffmpeg will error out and complain about something not working in the output format – like 48kHz audio in an FLV file (which is not allowed) – but that is a very good starting point for figuring out what you need to adjust in your ffmpeg command line.

Credit: All above documentation comes to us from Troy Strum – thanks, Troy!

Measure carefully. Photo (CC-BY) Joe Sullivan.

CDM is a home for people who make and play music and motion.