Converting Video Formats with FFmpeg
There are a times when you will want to encode a video using a particular codec and file format. FFmpeg lets you choose the codec with which you want to encode by adding -vcodec codec to the command line, where codec is the name of the codec you want to use. So if we want to encode using the MPEG-4 codec at 1,200kbps video bitrate and 128kbps audio bitrate, the command looks like this:
ffmpeg -i InputFile.mpg -ab 128 -b 1200 -vcodec mpeg4 OutputFile.avi
Let's say you have recorded a video that has a lot of background noise and undesired commentary, so you decide to remove the audio component of the video completely. To accomplish this, all you have to do is add the -an option to the command line, and FFmpeg automatically removes all audio from the output. Keep in mind that using this option negates any other option that affects the audio stream.
So, in our example, to remove the audio component, we would run the following command:
ffmpeg -i InputFile.mpg -an -b 1200 OutputFile.avi
Let's say you downloaded a news video from the Net that you want to listen to on your iPod on the way to work, but in order to do that, you have to remove the video component from the output file. FFmpeg allows you to remove the video component of the file completely by adding the -vn option to the command line. Using this option negates any other option that affects the video stream.
So, in our example, to remove the video component and save the audio as a 256kbps MP3 file, we would run the following command:
ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3
Many DVDs have multiple language tracks available, and you can choose in which language you want to watch the video. Having multiple audio tracks is cool if you speak multiple languages and want to be able to watch videos in multiple languages. However, if you don't speak multiple languages, the extra audio tracks are useless and are taking up disk space.
FFmpeg lets you choose which streams you want to keep and ignore the rest. The command-line parameter that allows you to map streams is called -map. So, if in our test file, stream 0 is the video stream, stream 1 is the Spanish audio stream and stream 2 is the English audio stream, and we want to keep the English audio in the output file, we would issue the following command:
ffmpeg -i InputFile.mpg -map 0:0 -map 2:1 -b 1200 OutputFile.avi
In my experience, stream 0 in most video files is usually the video stream, and the remaining streams are the audio streams available with the video.
FFmpeg provides a wide range of options for manipulating and converting video files between a variety of formats. For more information, or to download the latest version of FFmpeg for yourself, please refer to the project Web site.
Suramya Tomar is a Linux system administrator who also likes to program. Visit www.suramya.com for more information on his background.
|diff -u: What's New in Kernel Development||Sep 04, 2015|
|Android Candy: Copay—the Next-Generation Bitcoin Wallet||Sep 03, 2015|
|The True Internet of Things||Sep 02, 2015|
|September 2015 Issue of Linux Journal: HOW-TOs||Sep 01, 2015|
|September 2015 Video Preview||Sep 01, 2015|
|Using tshark to Watch and Inspect Network Traffic||Aug 31, 2015|
- diff -u: What's New in Kernel Development
- Problems with Ubuntu's Software Center and How Canonical Plans to Fix Them
- September 2015 Issue of Linux Journal: HOW-TOs
- Android Candy: Copay—the Next-Generation Bitcoin Wallet
- Using tshark to Watch and Inspect Network Traffic
- The True Internet of Things
- Firefox Security Exploit Targets Linux Users and Web Developers
- Build a “Virtual SuperComputer” with Process Virtualization
- Doing Astronomy with Python
- My Network Go-Bag