|
Now that you have successfully installed ffmpeg we can start experimenting with it. The first thing you have to do is choose a video file to experiment with. As this is your first time with ffmpeg, making a backup copy of this file is highly recommended. You don’t want to be responsible for ruining the only copy of a rare video.
This input file has most probably been encoded using a particular codec but since ffmpeg supports most of the popular formats, we don't need to worry a lot about that. Formats supported by ffmpeg include MPEG, MPEG4 (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
A detailed list of supported file formats is also available at the ffmpeg site [2].
ffmpeg supports a large list of command line parameters that control various settings in ffmpeg. To get a listing of the various options available run the following command:
ffmpeg --help
Don't let the multi page listing scare you from using ffmpeg, the basic usage is actually very simple. To convert a file with the default settings run the following command:
ffmpeg -i InputFile OutputFile
The -i flag tells ffmpeg that the filename immediately after it is the name of the file to be used as input. If this flag is omitted then ffmpeg will attempt to overwrite that file when it tries to create the output file. ffmpeg uses the extension of the output file to try and determine the format and codec to use, though this can be overridden using command line parameters. (More on this later)
The default settings create an output file which has radio quality sound (64kbit/s bitrate) and very bad video quality (200 kbit/s bitrate). Fortunately these settings can be changed for each encoding, which allows us to choose the quality of each file depending on the need.
To change the audio bitrate we add the '-ab bitrate' to the command we used earlier, where bitrate is the bitrate we want to use [3]. I prefer to encode files with a bitrate between 128 - 192 kbit/s depending my needs but you can put in a higher value if you so desire, however keep in mind that the higher bitrate you use the larger the output file size will be. Also keep in mind that if your source file is encoded in a low bitrate then increasing the bitrate won't accomplish much other than increase the output file size.
Now getting a CD quality audio track for the video doesn't really make sense if the video looks like it was taken using a 5 year old web-cam having a bad day. Thankfully this problem is also easily solved by adding another parameter to our command line.
To change the video bitrate we add the '-b bitrate' switch to the command line. The bitrate here can be any numeric value you like and I have seen bitrates all the way up to 23,000 (DVD Rips). While the quality of video encoded with a 23,000 kbit/s bitrate is amazing, the resulting file size of that encoding is also very amazing (a 90 min video is about 4 GB). In my experience most videos look pretty decent at bitrates between 1000 - 1400 but this is a personal preference so play with the numbers till you figure out what works for you.
So to encode a video with a 128 kbit/s Audio bitrate and a 1200 kbit/s video stream we would issue the following command:
ffmpeg -i InputFile.avi -ab 128 -b 1200 OutputFile.mpg

Fig 1.0 ffmpeg in action, converting an avi file to mpeg1 file
If you are creating a video CD or a DVD then ffmpeg makes it even easier for you by letting you specify a target type and then uses it to automatically calculate the format options required. To set a target type add '-target type' where type can be "vcd", "svcd", "dvd", "dv", "pal-vcd" or "ntsc-svcd" to the command line. So if we were creating a VCD we would run the following command:
ffmpeg -i InputFile.mpg -target vcd vcd_file.mpg
ffmpeg also has support for encoding audio files and the command to convert audio files is the same as the command to encode video files. So to convert a wave file to a 128 kbit/s mp3 file we would issue the following command:
ffmpeg -i Input.wav -ab 128 Output.mp3
Now the biggest selling point of ffmpeg is that you can customize it to a level that you are comfortable with. So if all you want to do is convert from one codec to another and don't really care about the advanced features then you can stop reading over here and still be able to encode/decode videos. On the other hand if you like to have more control over the encoding read on ahead as the next section covers some of the advanced options available in ffmpeg.
|