How to convert audio with FFmpeg: WAV, MP3, AAC, FLAC, and batch processing

FFmpeg handles audio format conversion in a single command: ffmpeg -i input.wav output.mp3. The key flags are -b:a for bitrate, -ar for sample rate, and -ac for channel count.

INEZA Felin-Michel

INEZA Felin-Michel

10 April 2026

How to convert audio with FFmpeg: WAV, MP3, AAC, FLAC, and batch processing

TL;DR

FFmpeg handles audio format conversion in a single command: ffmpeg -i input.wav output.mp3. The key flags are -b:a for bitrate, -ar for sample rate, and -ac for channel count. For batch processing, loop the command over files or use FFmpeg’s glob patterns. If your workflow connects to AI audio APIs, test them with Apidog to verify request/response handling before integrating.

button

Introduction

Audio conversion is one of FFmpeg’s most common uses. You receive a WAV file from a recording workflow and need MP3 for web delivery. You get FLAC from a music production pipeline and need AAC for a mobile app. FFmpeg handles all of these from the command line with no graphical interface required.

This guide covers the most common audio conversions, the flags that matter, batch processing patterns, and how to troubleshoot common errors.

Installation

If FFmpeg isn’t installed:

macOS:

brew install ffmpeg

Ubuntu/Debian:

sudo apt install ffmpeg

Windows:Download from ffmpeg.org and add the bin folder to your PATH.

Verify with:

ffmpeg -version

Basic conversion syntax

The base command structure:

ffmpeg -i input_file.ext output_file.ext

FFmpeg infers the format from the file extension. For most conversions, this is enough.


Common audio conversions

WAV to MP3

ffmpeg -i recording.wav -b:a 192k output.mp3

-b:a 192k sets the audio bitrate to 192 kbps. Common values:

For spoken word (podcasts, voice notes), 128k is sufficient. For music, 192k or higher.

FLAC to AAC

ffmpeg -i lossless.flac -c:a aac -b:a 256k output.aac

-c:a aac explicitly sets the codec. Without it, FFmpeg guesses from the output extension, which usually works but explicit is safer.

MP3 to WAV

ffmpeg -i compressed.mp3 output.wav

This decodes MP3 to PCM WAV. The output file will be much larger; WAV is uncompressed.

OGG to MP3

ffmpeg -i podcast.ogg -b:a 192k output.mp3

M4A to MP3

ffmpeg -i track.m4a -b:a 192k output.mp3

Audio quality flags

Bitrate

-b:a 192k sets a constant bitrate (CBR). For variable bitrate (VBR):

ffmpeg -i input.wav -q:a 2 output.mp3

-q:a ranges from 0 (highest quality) to 9 (lowest). Values 0-2 produce near-lossless MP3; 5-7 produce acceptable quality for speech.

Sample rate

ffmpeg -i input.wav -ar 44100 output.mp3

-ar 44100 sets 44.1 kHz (CD quality). Common values: 22050 (half quality, smaller file), 44100 (standard), 48000 (professional audio/video).

Channels

ffmpeg -i stereo.wav -ac 1 mono.mp3

-ac 1 converts stereo to mono. Useful for voice content where stereo adds no value.


Controlling output quality

For MP3 encoding, the libmp3lame encoder gives more control:

ffmpeg -i input.wav -c:a libmp3lame -b:a 192k -ar 44100 -ac 2 output.mp3

For AAC, use the aac codec with quality mode:

ffmpeg -i input.wav -c:a aac -q:a 1.5 output.aac

Batch processing

Shell loop (macOS/Linux)

for file in *.wav; do
  ffmpeg -i "$file" -b:a 192k "${file%.wav}.mp3"
done

This converts all .wav files in the current directory to .mp3. The ${file%.wav} strips the .wav extension.

Batch with output directory

mkdir output
for file in *.flac; do
  ffmpeg -i "$file" -c:a aac -b:a 256k "output/${file%.flac}.aac"
done

Powershell (Windows)

Get-ChildItem *.wav | ForEach-Object {
  $output = $_.BaseName + ".mp3"
  ffmpeg -i $_.FullName -b:a 192k $output
}

Trimming during conversion

Convert and trim to a specific segment in one command:

ffmpeg -i input.mp3 -ss 00:01:30 -t 60 -b:a 192k clip.mp3

-ss 00:01:30 starts at 1 minute 30 seconds. -t 60 captures 60 seconds of audio.

Using -to instead of -t to specify end time:

ffmpeg -i input.mp3 -ss 00:01:30 -to 00:02:30 output.mp3

Common errors and fixes

“No such file or directory”
Check the input path. FFmpeg is path-sensitive; if the file has spaces, quote the path: ffmpeg -i "my file.wav" output.mp3.

“Invalid data found when processing input”
The file may be corrupted or misnamed. Try ffmpeg -i filename without an output to inspect the file’s actual format.

“Conversion failed!” with codec errors
Some codecs require specific encoders. Add -c:a libmp3lame for MP3 or -c:a aac for AAC if the default fails.

Output file is larger than expected
You may be converting from a compressed format (MP3) to WAV or FLAC. Uncompressed output is always larger.


Integrating with AI audio APIs

Many applications use audio conversion as a preprocessing step before sending audio to AI APIs (speech transcription, sentiment analysis, speaker identification).

A typical pipeline:

  1. Receive audio in any format (WAV, MP3, M4A)
  2. Convert to the format your AI API requires (usually WAV 16kHz mono for speech APIs)
  3. POST to the API

For the conversion step:

ffmpeg -i input.m4a -ar 16000 -ac 1 -c:a pcm_s16le processed.wav

-ar 16000 sets 16 kHz (most speech APIs require this). -ac 1 converts to mono. -c:a pcm_s16le outputs 16-bit little-endian PCM, the standard for speech recognition.

Testing the API with Apidog:

Once you have the processed audio, test your AI API endpoint in Apidog before building the integration:

POST https://api.speech-service.example.com/v1/transcribe
Authorization: Bearer {{API_KEY}}
Content-Type: multipart/form-data

[audio_file: processed.wav]
[language: en-US]

Add assertions to catch unexpected response structures before they cause silent errors in production:

Status code is 200
Response body has field transcript
Response body, field confidence is greater than 0.7

FAQ

Does FFmpeg lose quality when converting between compressed formats?
Yes. Converting MP3 to AAC decodes and re-encodes, introducing generation loss. For archival, convert to a lossless format first. For direct distribution, convert from the original uncompressed source if possible.

What’s the best format for web audio?
MP3 has the widest browser support. AAC is slightly more efficient at the same bitrate. OGG Vorbis is open-source with good quality. For most cases, MP3 at 128-192k is the safe choice.

How do I check what format an audio file is actually in?

ffmpeg -i filename.mp3

This prints file info without converting. Look for “Audio:” in the output to see the actual codec and format.

Can FFmpeg convert audio and video together?
Yes. -c:v copy -c:a aac copies the video stream while re-encoding just the audio, which is faster than re-encoding both.

Explore more

HappyHorse-1.0 vs Seedance 2.0: which AI video model wins right now?

HappyHorse-1.0 vs Seedance 2.0: which AI video model wins right now?

HappyHorse-1.0 leads on visual quality benchmarks (T2V Elo 1333 vs Seedance 2.0’s 1273) but has no stable API and no consumer access. Seedance 2.0 has a ByteDance backing, consumer access via Dreamina, and leads on audio generation

10 April 2026

Best free AI face swapper in 2026: no signup options, API access, ethical use

Best free AI face swapper in 2026: no signup options, API access, ethical use

The best free AI face swappers in 2026 are WaveSpeedAI (no-signup web tool, full REST API, consent-first design), Reface (mobile app), DeepFaceLab (open source desktop), Akool (API-ready), and Vidnoz (web-based).

10 April 2026

How to use Google Genie 3: interface walkthrough, generation tips, and what to expect

How to use Google Genie 3: interface walkthrough, generation tips, and what to expect

Google Genie 3 is a sketch-to-video model in limited research access as of early 2026. Access is through experimental demos and select partner pilots, not a public API.

10 April 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs