How to use FFMpeg to do Simple Audio Conversion

Here's a simple FFmpeg how to that will cover just a portion of the framework's abilities. We will see how you can use the terminal to perform simple conversions of various audio file types including all popular and widely available formats. Using FFmpeg right from the terminal makes it better for performance compared to downloading and installing a GUI tool for FFmpeg, and can also offer more precise settings for the advanced users.

Convert Audio Files with FFMPeg

Beginning with audio conversion, I will be using two samples from Cut Chemist's live performances that are of mp3 and aif file types. Before initiating anything, make sure that you have Ffmpeg installed in your system. To do this, open a terminal and type:

ffmpeg –version

and something like that shown in the following screenshot should appear.

Check ffmpeg version


If FFmpeg is missing you can easily install it right from the same terminal by typing:

sudo apt-get install ffmpeg

if you're using Ubuntu, or:

yaourt ffmpeg

if you are an Arch user. Whatever your distribution of choice, you will most certainly find ffmpeg available in your package manager. The addition of an extra repository may be necessary.


Now if you type:

ffmpeg –help

on a terminal, you will get a picture of the power of the framework. You can use it to determine or change the volume, the audio channels, the sampling rate and so much more. Starting with the basics though, lets see how to convert both our files into wav types.

Open a terminal and go inside the folder that contains the input files (the files that are going to be converted). Ideally you can use the file manager to get there and then press right click on empty space and 'open a terminal here'. From then you can enter the following command:

ffmpeg -i filename.mp3 newfilename.wav

Here's my example:

Convert MP3 to WAV File format

In this case I renamed the file and converted it to a wav type of audio file.

Ok that was easy, but how can we determine what are the supported file types that we can convert from/to? That is as simple as typing

ffmpeg -formats

and

ffmpeg -codecs

and all supported forms will be displayed.

You can use one input file to get several different output files by just entering the name and the prefix like this:

ffmpeg -i filename.mp3 newfilename.wav newfilename.ogg newfilename.mp4

This will result in converting 3 output audio files (wav,ogg,mp4) from one mp3 file. Alternatively, you can set the desired codec using the -c command like this:

ffmpeg -i filename.mp4 c:a libopus newfilename.ogg

Now let's say we want to convert the other file I have here that is an aif to an mp3, but we don't want any kind of mp3. Suppose that we want to determine the bitrate for the output file. To do this you need to enter it in the following way:

ffmpeg -i filename.aif -b:a 320000 newfilename.mp3

Note that the bitrate is measured in bits/sec so if I want 320kbit/s I need to enter 320000.

Here's my example:

Convert AIF to MP3 or MP4 to OGG

This was just an introduction to FFmpeg's vast abilities and I hope it works as some kind of incentive for you to further discover the advanced framework.
These could be your first steps into conquering this powerful tool called FFmpeg, or just another way to do things in a more simple and understandable way. Whatever the case, you need to get deep into digging FFmpeg's amazing documentation (https://www.ffmpeg.org/documentation.html) and hopefully you'll find a lot of cool stuff to play with if you're interested.

Share this page:

12 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: emarsk

I'd highlight another feature: it converts automatically metadata tags (from flac to mp3's id3, for example).

Also, an essential option for me is the mp3 quality setting:

ffmpeg -i input.flac -q:a 2 out.mp3

This is the same as using "lame -V2", but directly from flac, and with tag conversion :)

By: brijmohan karadia

I  have an issue regarding merging videos, can you help me  plz?

By: Amol

Can we do the same for bulk of wav files into m4a?like 50wav files can be convert in m4a at a time could you suggest?

By: daveclark966

another option:you can use Avdshare Audio Converter to convert between any audio format.

By: daveclark966

To convert AIFF to M4A, you will use Avdshare Audio Converter which is the most popular AIFF to M4A converter recommended by users.

By: jraju

Hi, nice article.

please say how to use ffmpeg to change only audio format in a video file. i used one such formula and it processed . but i could not find the output file in the source folder or elsewhere.

for eg. ffmpeg -i abc.mp4 acodec mp3 out.mp4, where in i could not locate the out.mp4. what i miss

But it processes the request and finishes with the command prompt

By: daveclark966

Avdshare Audio Converter can Easily increase any MP3 bitrate, like converting 128 bitrate to 256 bitrate, converting 128 bitrate to 320 bitrate, converting 256 bitrate to 320 bitrate, etc.

By: marc

 confusing that you're converting .wav to .mp3, something that no one actually does...

By: Max

actually I do this alot. When quality doesnt matter it uploads a lot faster than .wav since its a smaller file.

By: Nipon

Will the audio file properties like bitrate and sampling rate will change after converting to other formats?

By: Mohana krishnan

Can I use ffmpeg in angular 6 for audio conversion?

By: DannyLox

https://issues.apache.org/jira/browse/AAR-9373