Convert Audio & Video Files With ffmpeg In Ubuntu 17.10 Artful Aardvark

From time to time you may need to extract the sound from a video file. Fortunately, using the ffmpeg program, it’s quite simple to take the sound from any video file and store it as a separate file. The ffmpeg utility can convert back and forth between multiple formats of both video and sound. Even better, in keeping with the overall theme of this book, ffmpeg is a command-line utility.

Here’s how to install and use ffmpeg on Ubuntu.

First, you’ll need to install the Ubuntu Restricted Extras package so ffmpeg can effectively move files between formats, which we described how to do earlier in this chapter.

After you’ve installed the Ubuntu Restricted Extras, use this command to install ffmpeg:

sudo apt-get install ffmpeg

After the installation is complete, you can use ffmpeg to extract the audio from a video file. Say, for example, you have a video file named test.avi. To extract the audio to a file named audio.mp3, use ffmpeg with these options and arguments:

ffmpeg -i test.avi audio.mp3

This will create an audio file named audio.mp3 containing the sound from the video file. However, by default ffmpeg creates audio files with a bitrate of 64 kbps, which results in very low-quality audio. To force ffmpeg to create the mp3 file at the 256 kbps bitrate, add the -ab option to the command:

ffmpeg -i test.avi -ab 256k audio.mp3

This will create a higher-quality mp3 file, and you can use this modified command to extract the audio from any compatible video file.

The ffmpeg utility can do many other conversions as well – be sure to read the entire manual page for ffmpeg with this command:

man ffmpeg

Was this post helpful? These books might be useful: