How to Read AMR-NB Audio Files with FFmpeg

This article provides a straightforward guide on how to read, decode, and play Adaptive Multi-Rate Narrowband (AMR-NB) audio files using the FFmpeg command-line tool. You will learn how to verify your FFmpeg installation’s compatibility with the AMR format, play AMR-NB files directly from your terminal, and convert them into widely compatible audio formats like WAV or MP3.

Verifying AMR-NB Support in FFmpeg

Before attempting to read AMR-NB files, you must ensure your FFmpeg build has the necessary decoders enabled. FFmpeg typically decodes AMR-NB using the libopencore_amrnb external library.

To verify that your FFmpeg installation supports AMR-NB decoding, run the following command in your terminal:

ffmpeg -decoders | grep amr

If your installation is compatible, you will see amrnb or libopencore_amrnb listed with a D (indicating decoding capability) next to it.

Playing AMR-NB Files Directly

If you simply want to listen to the AMR-NB file, you can use ffplay, a command-line media player that comes bundled with FFmpeg. Execute the following command:

ffplay input.amr

This will initialize playback of the audio file directly in your terminal.

Converting AMR-NB to WAV or MP3

Because AMR-NB is a legacy format primarily used in mobile telecommunications, you may need to read and extract the audio data to a more modern format. FFmpeg handles this decoding and encoding process seamlessly.

To decode AMR-NB and convert it into a lossless WAV file, use:

ffmpeg -i input.amr output.wav

To convert AMR-NB to a highly compatible MP3 file, use:

ffmpeg -i input.amr -b:a 128k output.mp3

In these commands: * -i input.amr specifies the input AMR-NB file to be read. * -b:a 128k sets the audio bitrate for the output MP3 file. * output.wav or output.mp3 is the resulting file containing the decoded audio stream.