Roshan Book

My Tech Notebook

FFmpeg cheat sheet


Source: http://www.webupd8.org/2009/08/ffmpeg-cheat-sheet-19-best-practices.html

ffmpeg is a multiplatform, open-source library for video and audio files. It is usualy available in your distribution repositories, so search for it and install it. For Ubuntu:

sudo apt-get install ffmpeg

Because certain codecs are not activated for FFmpeg in Ubuntu Jaunty, I suggest you download and install these ffmpeg fixed packages (unfortunately they are available for 32bit only).

Now that you have installed ffmpeg, you can start trying these commands which cover almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more:

Getting info from a video file

ffmpeg -i video.avi

Turn X images to a video sequence

ffmpeg -f image2 -i image%d.jpg video.mpg

This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

Turn a video to X images

ffmpeg -i video.mpg image%d.jpg

This command will generate the files named image1.jpg, image2.jpg, …

The following image formats are also available : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

Encode a video sequence for the iPpod/iPhone

ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4

Explanations :

* Source : source_video.avi
* Audio codec : aac
* Audio bitrate : 128kb/s
* Video codec : mpeg4
* Video bitrate : 1200kb/s
* Video size : 320px x 180px
* Generated video : final_video.mp4

Encode video for the PSP

ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Explanations :

* Source : source_video.avi
* Audio codec : aac
* Audio bitrate : 32kb/s
* Video codec : xvid
* Video bitrate : 1200kb/s
* Video size : 320px x 180px
* Generated video : final_video.mp4

Extracting sound from a video, and save it as Mp3

ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3

Explanations :

* Source video : source_video.avi
* Audio bitrate : 192kb/s
* output format : mp3
* Generated sound : sound.mp3

Convert a wav file to Mp3

ffmpeg -i source_song.wav -vn -ar 44100 -ac 2 -ab 192 -f mp3 final_song.mp3

Convert .avi video to .mpg

ffmpeg -i source_video.avi final_video.mpg

Convert .mpg to .avi

ffmpeg -i source_video.mpg final_video.avi

Convert .avi to animated gif (uncompressed)

ffmpeg -i source_video.avi animated_gif.gif

Mix a video with a sound file

ffmpeg -i song.wav -i source_video.avi final_video.mpg

Convert .avi to .flv

ffmpeg -i source_video.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final_video.flv

Convert .avi to dv

ffmpeg -i source_video.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 final_video.dv

Or:

ffmpeg -i source_video.avi -target pal-dv final_video.dv

Convert .avi to mpeg for dvd players

ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 final_video.mpeg

Explanations :

* target pal-dvd : Output format
* ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
* aspect 16:9 : Widescreen

Compress .avi to divx

ffmpeg -i source_video.avi -s 320x240 -vcodec msmpeg4v2 final_video.avi

Compress Ogg Theora to Mpeg dvd

ffmpeg -i source_video.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 final_video.mpg

Compress .avi to SVCD mpeg2

NTSC format:

ffmpeg -i source_video.avi -target ntsc-svcd final_video.mpg

PAL format:

ffmpeg -i source_video.avi -target pal-svcd final_video.mpg

Compress .avi to VCD mpeg2

NTSC format:

ffmpeg -i source_video.avi -target ntsc-vcd final_video.mpg

PAL format:

ffmpeg -i source_video.avi -target pal-vcd final_video.mpg

Multi-pass encoding with ffmpeg

ffmpeg -i source_file -pass 2 -passlogfile ffmpeg2pass final_file-2

One response to “FFmpeg cheat sheet

  1. Instant Traffic Robot 2 March 26, 2012 at 6:44 am

    If you’re serious about making money with your website, watch this free video about getting free instant targeted traffic to your site http://instanttrafficrobot2.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: