Ffmpeg

From XPUB & Lens-Based wiki
Revision as of 15:01, 1 October 2013 by Michael Murtaugh (talk | contribs)


Powerful command line video tool originally written by Fabrice Bellard (under the pseudonym "Gerard Lantau")

Be sure to check you / print your own ffmpeg documentation!
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html

Usage

Like many "swiss army knife" commandline tools, ffmpeg has lots of options, with often many ways of doing something, and takes some getting used to.

-i INPUT

With ffmpeg you always use -i NAMEOFFILE to set an input, and eventually simply give another NAMEOFFILE at the end to specify an output. (NB: This is the opposite of tools like mencoder where -o sets an output, and input files are the default).

Inspect a video

Running ffmpeg with an input and no options / output dumps out information about a file. Despite the complaint that no output file has been specified, this command is very useful to check a video (file or URL!) for what kind of structure/format it has.

ffmpeg -i http://constantvzw.org:8000/variable.ogg

Convert a video into individual frames

The -r option sets the framerate. A framerate of .01 (or 1/100) means 100 seconds per frame. In this way you can easily make an overview of a movie:

ffmpeg -i rearwindow.avi -f image2 -y -r .01 -an rearwindow%06d.jpg

The "%06d" means to "pad" (or fill) the filename to having always 6 places (so adding extra 0's before the number as necessary so that the filenames all have the right size and avoiding any problem with sorting later). This follows the convention of the C printf command).

Extract 1 frame per second (padding to 3 places):

ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg

Setting a start time

Extract 2 fps (-r) starting at 1:45:02 (-ss) and process 10 seconds of the input (-t 10).

ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -t 10 image-%d.jpeg

Alternately -vframes lets you specify how many output frames you want (rather than input time)?

ffmpeg -i inputfile.avi  -r 2 -ss 01:45:02 -vframes 10 image-%d.jpeg

Assemble images into a video

ffmpeg -f image2 -r 1/5 -i img%03d.png -r 30 out.mp4

Resources