FFmpeg Tutorials

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. You can do basic to advanced multimedia enhancements, conversions, hd video encoding, and many more. Lot of applications and libraries support ffmpeg because of its power. Complete installation and instructions can be found from its official wiki here.

# This is my custom built ffmpeg
ffmpeg version git-2012-08-22-f92f493 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug 22 2012 21:35:53 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab --enable-libass --enable-libgsm --enable-openssl
  libavutil      51. 70.100 / 51. 70.100
  libavcodec     54. 54.100 / 54. 54.100
  libavformat    54. 25.104 / 54. 25.104
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 13.100 /  3. 13.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100

Type:

ffmpeg --help

for available options. Basic option of ffmpeg usage is:

ffmpeg -i inputFile.format outputFile.format

Audio file conversions:

ffmpeg -i audio.wav audio.mp3
# converts wav file to mp3
ffmpeg -i audio.wav -f mp3 audio.mp3
# -f: implicitly supply format
ffmpeg -i audio.wav -ab 128 -f mp3 audio.mp3
# -ab: audio bitrate, kbit/s
ffmpeg -i audio.wav -ab 128 -ar 42000 -f mp3 audio.mp3
# -ar: audio sampling frequency
ffmpeg -i audio1.mp3 -vol 300 audio2.mp3
# -vol: used to adjust volume
# For other audio formats, just do same commands above

Video encoding:

ffmpeg -i video.avi videoFinal.mpg
# basic video conversion
# you can use this command for mpg to avi, avi to mp4, ...
ffmpeg -i video.mpg -vcodec copy -acodec copy -b:v 1000 videoFinal.mkv
# converts mpg format to mkv
# -vcodec copy: the codec from its source
# -acodec copy: copy source audio codec
# you can use same command to other video formats
ffmpeg -i video.avi -vcodec libx264 -acodec libfaac -b:v 1000 -ab 128 videoFinal.mkv
# -vcodec: video codec (x264 for HD encoding and if you compiled ffmpeg with --enable-libx264)
# -acodec: audio codec (--enable-libfaac)
# -b:v - video bitrate, higher bitrate higher resolution but remember that it will output to bigger sizes
ffmpeg -i video.mpg -target dvd videoFinal.mpg
# -target: useful on format targetting when burning to cd/dvd
# target types are ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd")
#####################
# Source: http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs

ffmpeg -i video_origine.avi gif_anime.gif
# Convert .avi to animated gif(uncompressed)

ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
# Mix a video with a sound file

ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
# Convert .avi to .flv

ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
# Convert .avi to dv

ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg
Convert .avi to mpeg for dvd players

# End
#####################
# Source: http://forrst.com/posts/Linux_FFMpeg_for_screen_record_HD-4JZ
# Video sizes (for -s option)
# wsxga: 1600x1024, wuxga: 1920x1200, woxga: 2560x1600, wqsxga: 3200x2048
# wquxga: 3840x2400, whsxga: 6400x4096, whuxga: 7680x4800, cga: 320x200
# ega: 640x350, hd480: 852x480, hd720: 1280x720, hd1080: 1920x1080
# 16cif: 1408x1152, qqvga: 160x120, qvga: 320x240, vga: 640x480, svga: 800x600
# xga: 1024x768, uxga: 1600x1200, qxga: 2048x1536, sxga: 1280x1024
# qsxga: 2560x2048, hsxga: 5120x4096, wvga: 852x480, wxga: 1366x768, sqcif: 128x96
# qcif: 176x144, cif: 352x288, 4cif: 704x576

HD Screencasting

# Now for this part, you need to google what this options are coz I really don't know how I came up with this command. I just saved it on my snippet files. I think I found it somewhere in a forum and added my own settings.

ffmpeg -f alsa -i pulse -f x11grab -r 4 -s xdpyinfo | grep -i dimensions: | sed 's/[^0-9]*pixels.*(.*).*//' | sed 's/[^0-9x]*//' -i :0.0 -r 25 -vcodec libx264 -preset veryslow -crf 0 -threads 0 -y output.mkv

# view the output: vlc output.mkv

Note: These are not an advanced tutorials of ffmpeg but only to give you ideas about the awesomeness and power of ffmpeg and to help you get started.

Some helpful sites you might want to read, most of them are advanced tutorials.