FFmpeg - Encode MP3: Difference between revisions
Created page with "Category:FFmpeg Category:MP3 <pre> ffmpeg -i <input.file> -codec:a libmp3lame -qscale:a 2 <output.file> </pre> The transparency threshold for MP3 to linear PCM audio is said to be between 175 and 245 kbit/s, at 44.1 kHz, when encoded as VBR MP3…<br/> Reference: https://trac.ffmpeg.org/wiki/Encode/MP3 FFmpeg: FFmpeg MP3 Encoding Guide<br/> Reference: https://trac.ffmpeg.org/wiki/Encode/HighQualityAudio FFmpeg: Guidelines for high quality lossy audio encod..." |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category:FFmpeg]] | [[Category:FFmpeg]] | ||
[[Category:MP3]] | [[Category:MP3]] | ||
This article explains how to encode MP3 audio using FFmpeg with the libmp3lame encoder. It includes recommended variable‑bitrate (VBR) settings, transparency considerations, and references for deeper reading. | |||
FFmpeg does not include a native MP3 encoder. Instead, it relies on the high‑quality and widely respected LAME encoder. | |||
== Basic Command (VBR – Recommended) == | |||
Use the following command to encode a high‑quality VBR MP3 file: | |||
<pre> | <pre> | ||
ffmpeg -i <input.file> -codec:a libmp3lame -qscale:a 2 <output.file> | ffmpeg -i <input.file> -codec:a libmp3lame -qscale:a 2 <output.file> | ||
</pre> | </pre> | ||
The transparency threshold for MP3 | The option -qscale:a (alias: -q:a) controls the quality level instead of specifying a fixed bitrate. | ||
* Lower value = higher quality | |||
* Range for LAME: 0–9 | |||
* 0–3 → usually transparent | |||
* 4 → close to transparency | |||
* 6 → acceptable | |||
Using -qscale:a 2 corresponds to LAME’s -V 2 setting, producing a typical average bitrate of ~170–210 kbit/s at 44.1 kHz. | |||
== Transparency and Recommended Bitrates == | |||
The transparency threshold for MP3 is widely reported as being in the region of 175–245 kbit/s (VBR), 44.1 kHz. | |||
== Constant Bitrate (CBR) Encoding == | |||
If you need a fixed bitrate (e.g., for hardware compatibility), use: | |||
<pre> | |||
-b:a 128k | |||
</pre> | |||
Example: | |||
<pre> | |||
ffmpeg -i <input.file> -codec:a libmp3lame -b:a 256k <output.file> | |||
</pre> | |||
Available MP3 CBR bitrates (kbit/s): 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320. | |||
== Troubleshooting == | |||
Sometimes output bitrate is lower than expected due to bitrate boundaries, low‑bitrate input sources, or VBR optimisation. | |||
== Practical Examples == | |||
=== Convert 320k MP3 → Transparent VBR === | |||
<pre> | |||
ffmpeg -i in.mp3 -codec:a libmp3lame -qscale:a 2 out.mp3 | |||
</pre> | |||
=== Encode to low‑bitrate CBR === | |||
<pre> | |||
ffmpeg -i input.file -map 0:a:0 -b:a 96k output.mp3 | |||
</pre> | |||
== When to Use VBR vs CBR == | |||
* Use VBR when quality matters or transparency is desired. | |||
* Use CBR when device compatibility or predictable file size is required. | |||
== References == | |||
* FFmpeg MP3 Encoding Guide | |||
* FFmpeg High‑Quality Audio Encoding Guidelines | |||
Latest revision as of 14:36, 14 March 2026
This article explains how to encode MP3 audio using FFmpeg with the libmp3lame encoder. It includes recommended variable‑bitrate (VBR) settings, transparency considerations, and references for deeper reading.
FFmpeg does not include a native MP3 encoder. Instead, it relies on the high‑quality and widely respected LAME encoder.
Basic Command (VBR – Recommended)
Use the following command to encode a high‑quality VBR MP3 file:
ffmpeg -i <input.file> -codec:a libmp3lame -qscale:a 2 <output.file>
The option -qscale:a (alias: -q:a) controls the quality level instead of specifying a fixed bitrate.
- Lower value = higher quality
- Range for LAME: 0–9
- 0–3 → usually transparent
- 4 → close to transparency
- 6 → acceptable
Using -qscale:a 2 corresponds to LAME’s -V 2 setting, producing a typical average bitrate of ~170–210 kbit/s at 44.1 kHz.
Transparency and Recommended Bitrates
The transparency threshold for MP3 is widely reported as being in the region of 175–245 kbit/s (VBR), 44.1 kHz.
Constant Bitrate (CBR) Encoding
If you need a fixed bitrate (e.g., for hardware compatibility), use:
-b:a 128k
Example:
ffmpeg -i <input.file> -codec:a libmp3lame -b:a 256k <output.file>
Available MP3 CBR bitrates (kbit/s): 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320.
Troubleshooting
Sometimes output bitrate is lower than expected due to bitrate boundaries, low‑bitrate input sources, or VBR optimisation.
Practical Examples
Convert 320k MP3 → Transparent VBR
ffmpeg -i in.mp3 -codec:a libmp3lame -qscale:a 2 out.mp3
Encode to low‑bitrate CBR
ffmpeg -i input.file -map 0:a:0 -b:a 96k output.mp3
When to Use VBR vs CBR
- Use VBR when quality matters or transparency is desired.
- Use CBR when device compatibility or predictable file size is required.
References
- FFmpeg MP3 Encoding Guide
- FFmpeg High‑Quality Audio Encoding Guidelines