Learn the basics of audio manipulation and conversion with FFMPEG.
FFMPEG is available for nearly all Linux distributions.
A working Linux install with FFMPEG.
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
Audio formats are often easier to manage than video ones, but that doesn't mean that they don't come with their own headaches. For the most part, audio problems stem from DRM and losses in quality. While FFMPEG can't always help with DRM, it can help you to convert your files without losing quality.
First off, you need to learn the most basic way to convert an audio file.
$ ffmpeg -i song.mp3 song.ogg
FFMPEG uses the
flag to designate the beginning of input. After the input file(s), it looks for options and the output. In this case, only the output is present.
Not all audio formats are equal. Formats like
provide better quality audio than lossy formats like
. Regardless, you want to preserve as much quality as possible. To do that, include the
$ ffmpeg -i song.mp3 -sameq song.ogg
Audio compression decreases the quality of an audio file, but it also creates smaller audio files. The most common way of compressing audio files is decreasing the bitrate of the file.
To set the bitrate of an output file with FFMPEG, use the
$ ffmpeg -i song.mp3 -ab 192 song.ogg
There are several common bitrates that are used for compression. You can use any number of them, depending on your goal.
$ ffmpeg -i song.mp3 -ab 128 song.ogg
Frequency is another factor that determines the quality of the output file. Frequency refers to the sample rate. Higher sample rates help to prevent distortion.
You can set the sample rate with the
$ ffmpeg -i song.mp3 -ab 192 -ar 44100 song.ogg
If there is a particular codec that you'd prefer to use for encoding, you can specify that to FFMPEG with the
$ ffmpeg -i song.ogg -acodec libmp3lame song.mp3
FFMPEG obviously supports multiple codecs. Actually, it uses the output file type to guess them, but you can always explicitly specify them.
$ ffmpeg -i song.mp3 -acodec vorbis song.ogg
What happens if you want to strip the video out of a file and keep the audio? FFMPEG has you covered there too. Of course, you can use this in conjunction with another script like youtube-dl to truly automate the process.
$ ffmpeg -i video.mp4 -vn song.mp3
flag removes the video as it transcodes.
You can use FFMPEG to capture input from a microphone and save it to any output format that you like. By using the previous flags, you can control exactly how the file is saved.
$ ffmpeg -f alsa -i /dev/dsp -ar 44100 -ab 192 recording.flac
Before recording, check
for the mount point of your microphone. You can also use other notations to specify the hardware device you're using to record.
$ ffmpeg -f alsa -i hw:0 -ar 44100 -ab 192 recording.flac
FFMPEG is an amazing tool for working with audio files. If you're someone who is concerned with the quality of your music, FFMPEG can be an invaluable resource in ensuring that your are getting the absolute most of your music files.
If you're interested in learning more about FFMPEG, check out our video guide
to explore how to work with videos using FFMPEG.