FFmpeg Tricks You Should Know About

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. FFmpeg is free software and is licensed under the LGPL or GPL depending on your choice of configuration options.

FFmpeg supports most of the popular formats, we don’t need to worry a lot about that. Formats supported by FFmpeg include MPEG, MPEG-4 (Divx), ASF, AVI, Real Audio/Video and Quicktime. To see a list of all the codecs/formats supported by FFmpeg, run the following command:

ffmpeg-formats

1. X11 grabbing

FFmpeg can grab the X11 display.

ffmpeg-f x11grab -r24-s cif -i :0.0/tmp/out.mpg

0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable.

ffmpeg-f x11grab -r24-s cif -i :0.0+10,20/tmp/out.mpg

0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset for the grabbing.

ffmpeg-f x11grab -r25-s 800x600 -i :0.0/tmp/outputFile.mpg

2. Convert Pictures To Movie

First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,… Then you may run:

ffmpeg-f image2 -i img%d.jpg /tmp/a.mpg

Notice that `%d’ is replaced by the image number.

`img%03d.jpg' means the sequence `img001.jpg', `img002.jpg', etc…

If you have large number of pictures to rename, you can use the following command to ease the burden. The command, using the bourne shell syntax, symbolically links all files in the current directory that match *jpg to the `/tmp' directory in the sequence of `img001.jpg', `img002.jpg' and so on.

If you want to sequence them by oldest modified first, substitute $(ls -r -t *jpg) in place of *jpg.

Then run:

ffmpeg-f image2 -i/tmp/img%03d.jpg /tmp/a.mpg

The same logic is used for any image format that ffmpeg reads.

3. Video Conversions

Quick and dirty convert to flv

ffmpeg-i inputfile.mp4 outputfile.flv

This converts any media ffmpeg handles to flash. It would actually convert anything to anything, it’s based on the file extension. It doesn’t do ANY quality control, sizing, etc, it just does what it thinks is best.

8. Join Multiple Video Files

Hence you may concatenate your multimedia files by first transcoding them to these privileged formats, then using the humble cat command (or the equally humble copy under Windows), and finally transcoding back to your format of choice.