Downsample Audio to 8kHz with FFmpeg

Downsampling audio files to 8kHz is a standard requirement for telecommunication testing, as 8000 Hz is the traditional sample rate used in narrowband telephony (POTS and VoIP). This article provides a quick, step-by-step guide on how to use FFmpeg, a powerful command-line tool, to convert your audio files to 8kHz while adjusting channels and codecs specifically for telecom environments.

The Basic Downsampling Command

To change the sample rate of an audio file to 8kHz, you use the -ar (audio rate) flag. Open your terminal or command prompt and run the following command:

ffmpeg -i input.wav -ar 8000 output.wav

Optimizing for Telecom: Converting to Mono

Standard telecommunication channels only support single-channel (mono) audio. If your source file is in stereo, you should downmix it to mono using the -ac (audio channels) flag to ensure realistic test results.

ffmpeg -i input.wav -ar 8000 -ac 1 output.wav

Formatting for Specific Telecom Codecs

During telecom testing, you may need to simulate specific telephony codecs, such as G.711 (µ-law or A-law), which are the global standards for landline and mobile networks.

1. G.711 µ-law (Common in North America and Japan)

To output an 8kHz, mono, PCM mu-law file, use the following command:

ffmpeg -i input.wav -ar 8000 -ac 1 -codec:a pcm_mulaw output.wav

2. G.711 A-law (Common in Europe and the rest of the world)

To output an 8kHz, mono, PCM A-law file, use this command:

ffmpeg -i input.wav -ar 8000 -ac 1 -codec:a pcm_alaw output.wav

Batch Processing Multiple Files

If you have an entire folder of audio files that need to be downsampled to 8kHz for a test suite, you can automate the process.

On Windows (Command Prompt):

for %i in (*.wav) do ffmpeg -i "%i" -ar 8000 -ac 1 "8kHz_%i"

On Linux / macOS (Terminal):

for file in *.wav; do ffmpeg -i "$file" -ar 8000 -ac 1 "8kHz_$file"; done

These commands will process every .wav file in your current directory, downsampling them to 8kHz mono and saving the new files with an 8kHz_ prefix.