Skip to content


Manipulating, converting and editing audio and video

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It is a very fast video and audio converter and includes libavcodec which is the leading audio/video codec library. It can also grab from a live audio/video source.

The command line interface is very easy to use because the program figures out all the default parameters intelligently. Usually, the input file name with -i option and output file name is all you have to specify. In this tutorial, we will see how to get information about audio or video file, convert from one audio or video format to another, capture audio or video from a device and extracting audio or video from a multimedia file using ffmpeg.

Supported Formats

FFmpeg supports a number of formats like avi, wav, asf, mp3, mov, mp4,ogg, vcd, wmv and a lot more. To see which formats it supports, use -formats option

ffmpeg -formats
File formats:
  E 3g2             3gp2 format
  E 3gp             3gp format
 D  4xm             4X Technologies format
 D  RoQ             Id RoQ format
 D  aac             ADTS AAC
 DE ac3             raw ac3
  E adts            ADTS AAC
 DE aiff            Audio IFF
 DE alaw            pcm A law format
 DE amr             3gpp amr file format
 DE asf             asf format
  E asf_stream      asf format
 DE au              SUN AU Format
 DE audio_device    audio grab and output
 DE avi             avi format
 D  avs             avs format
  E crc             crc testing format
 D  daud            D-Cinema audio format
 .......
 .......

Getting information about audio or video file

It is super easy to get information about a particular multimedia file. The only option it takes is -i and the input file name

ffmpeg -i file.mp3
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
  configuration:  --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
  libavutil version: 0d.49.0.0
  libavcodec version: 0d.51.11.0
  libavformat version: 0d.50.5.0
  built on Apr 26 2009 11:34:57, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, mp3, from 'file.mp3':
  Duration: 00:12:00.7, start: 0.000000, bitrate: 55 kb/s
  Stream #0.0: Audio: mp3, 22050 Hz, stereo, 56 kb/s
Must supply at least one output file

The first line shows the version of ffmpeg which is unknown in this case because it was compiled from svn revision. Then we have the options that ffmpeg was compiled with. Next lines shows information about the version of utilities and codec used by ffmppeg.

The interested lines are
Duration: 00:12:00.7, start: 0.000000, bitrate: 55 kb/s
Stream #0.0: Audio: mp3, 22050 Hz, stereo, 56 kb/s

which tell us that the duration of the track is 12 minutes and 7 seconds, codec used is mp3 of sample rate 22050Hz, there are two audio channels (stereo) and the resulting bitrate is 56kbit/s.

Converting video from one format to another

Let’s say we have a movie that is in wav file format and we want to convert it into avi. The following will easily do that for us

ffmpeg -i input_file.wav output_file.avi

where input_file is the format we want to transcode and output_file is the format we want the converted file to be.

To change avi to mp3, run the following command

ffmpeg -i file.avi file.mp3

To convert avi to dvd for ntsc (playable mostly in North America), use the -target option

ffmpeg -i file.avi -target ntsc-dvd file.mpg

we can specify the aspect ratio too with -aspect option

ffmpeg -i file.avi -target ntsc-dvd -aspect 4:3 file.mpg

If our original movie file was in wav format, we would convert it into dvd as follows

ffmpeg -i file.wav -target ntsc-dvd -aspect 4:3 file.mpg

Similarly, if the original file is a flash video, we need this command

ffmpeg -i file.flv -target ntsc-dvd -aspect 4:3 file.mpg

To convert asf to avi

ffmpeg -i file.asf file.avi

Likewise, we can change swf file to mov file for playing with Qicktime

ffmpeg -i file.swf file.mov

Say you have an avi movie and you want to convert it into vcd so you can play it on normal cd player, run the follwoing command

ffmpeg -i movie.avi -target pal-vcd movie.mpg

In the examples above we can specify video codecs with -vcodec, audio codec with -acodec, size with -s, frame bit rate with -r, video bit rate with -b, audio frequency with -ar, audio bit rate -ab and -f to force a particular format. The following example will convert the mpg file to avi using mpeg4 video codec with size 320×240 and video bit rate 300kbit/s. It will use mp3 audio codec, 64 kbit/s audio bit rate and audio frequency of 22050 KHz. It will also force avi format

ffmpeg -i file.mpg -vcodec mpeg4 -s 320x240 -b 300k -r 10 -acodec mp3 -ar 22050 -ab 64k -f avi file.avi

If any of the options are ommitted, ffmpeg will use the defaults.

Cropping and padding video

You can crop a movie from top, bottom, left or right. To trim 25 pixels from top and 25 pixles from bottom of our movie file, we would run the following command

ffmpeg -i file.avi -croptop 25 -cropbottom 25 file_crop.mpg

To put bars at top and bottom to pad the movie at top and bottom by 20 and 30 pixels respectively with white pad color, run the following command

fmpeg -i file.mpg -padtop 44 -padbottom 46 -padcolor 000000 -f avi file_pad.avi

Extracting audio from video

This is my favorite because I have to do it all the time to strip off audio from stand-up comedy shows. To extract audio from George Carlin’s (my favorite) show names show.avi, use the -vn option to ffmpeg

ffmpeg -i show.avi -vn show_audio.mp3

Capturing audio and video

FFmpeg can use a video4linux compatible video source and any Open Sound System audio source. To capture audio and video, use the following command

ffmpeg /tmp/out.mpg

Please stay tuned as I may add more tips to this article in the future.

For further information visit ffmpeg official site

 

 

Share The Knowledge:
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • blogmarks
  • Diigo
  • E-mail this story to a friend!
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Twitter
  • Blogosphere News
  • Identi.ca
  • Slashdot
  • Technorati

Posted in Centos, Debian, Fedora, Red Hat, Ubuntu.


7 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. The Doctor says

    Winff is a graphical interface for ffmpeg.

  2. Pat says

    Thanks for the article, very useful!

  3. Pat says

    Thanks for the article, very helpful!

  4. Bobber says

    Is it possible to replace the source audio of a video file with a different source of higher quality?

  5. Fred says

    Thank you !
    For me very usefull.
    Keep on the good work

  6. dumper4311 says

    Thanks for the article. Your final “Capturing Audio and Video” example seems incomplete, but otherwise good info.

Continuing the Discussion



Some HTML is OK

or, reply to this post via trackback.