How to Set Target Audio Bitrate in FFmpeg
This article provides a straightforward guide on how to set a target average bitrate for audio streams using FFmpeg. You will learn the exact command-line arguments needed to control audio quality, see practical examples for popular formats like AAC and MP3, and understand how the bitrate flag behaves across different audio codecs.
To set the target average bitrate for an audio stream in FFmpeg, you
use the -b:a option (which is an alias for
-ab). This option tells the encoder the desired average
bitrate for the output audio stream.
Basic Command Syntax
The basic syntax for setting the audio bitrate is:
ffmpeg -i input.mp4 -c:a <codec> -b:a <bitrate> output.mp4-i input.mp4: Specifies the input file.-c:a <codec>: Specifies the audio encoder (e.g.,aac,libmp3lame,libopus).-b:a <bitrate>: Specifies the target average bitrate (e.g.,128k,192k,320k).
Example 1: Setting AAC Audio Bitrate (MP4/M4A)
AAC is the standard audio codec for MP4 containers. To set the target audio bitrate to 192 kbps while copying the video stream without re-encoding, use the following command:
ffmpeg -i input.mp4 -c:v copy -c:a aac -b:a 192k output.mp4Example 2: Setting MP3 Audio Bitrate
To convert an audio file to MP3 with a target average bitrate of 320 kbps using the LAME encoder, run:
ffmpeg -i input.wav -c:a libmp3lame -b:a 320k output.mp3Example 3: Setting Bitrate for Specific Streams
If your input file has multiple audio streams, you can target a specific stream by index. For example, to set the bitrate of the first audio stream to 128 kbps and the second audio stream to 256 kbps, use:
ffmpeg -i input.mkv -b:a:0 128k -b:a:1 256k output.mkvAverage Bitrate (ABR) vs. Constant Bitrate (CBR)
Using the -b:a flag generally tells the encoder to
target an Average Bitrate (ABR).
- ABR/VBR: Encoders like
aacandlibopuswill dynamically allocate bits, using more bits for complex audio parts and fewer bits for simple parts, while aiming to keep the overall file size close to your target-b:avalue. - CBR: If you strictly require Constant
Bitrate (CBR) (where every second of audio uses the exact same
number of bits), some encoders require additional flags, though many
will default to CBR-like behavior when
-b:ais specified without variable bitrate flags.