I success with this command
In our example above, we selected -qscale:a 2, meaning we used LAME's option -V 2, which gives us a VBR MP3 audio stream with an average stereo bitrate of 170-210 kBit/s.
Another option if you have a lossless source is to transcode it to another lossless codec, like flac .
This post on hydrogenaudio.org demonstrates what will happen if you re-encode a file 100 times: http://www.hydrogenaud.io/forums/index.php?showtopic=100067
Example:
Transcoding a WebM file (with VP8 video/Vorbis audio) to a MKV file (with H.264 video/unaltered Vorbis audio):
Here are some popular lossy formats with encoders listed that FFmpeg can use:
This list is just a general guide and there may be cases where a codec listed to the right will perform better than one listed to the left at certain bitrates.
The highest quality internal/native encoder available in FFmpeg without any external libraries is aac.
Please note it is not recommended to use the experimental vorbis for Vorbis encoding; use libvorbis instead.
Please note that wmav1 and wmav2 don't seem to be able to reach transparency at any given bitrate.
Please note that there are more container formats available than those listed above.
The wmav1/wmav2 encoder does not reach transparency at any bitrate.
The vorbis encoder does not use the bitrate specified in FFmpeg. On some samples it does sound reasonable, but the bitrate is very high.
To calculate the bitrate to use for multi-channel audio: (bitrate for stereo) x (channels / 2).
Example for 5.1(6 channels) Vorbis audio: 128Kbps x (6 / 2) = 384Kbps
When compatibility with hardware players doesn't matter then use libvorbis in a MKV container when libfdk_aac isn't available.
When compatibility with hardware players does matter then use libmp3lame or ac3 in a MP4/MKV container when libfdk_aac isn't available.
Transparency means the encoded audio sounds indistinguishable from the audio in the source file.
Some codecs have a more efficient variable bitrate (VBR) mode which optimizes to a given, constant quality level rather than having variable quality at a given, constant bitrate (CBR). The info above is for CBR. VBR is more efficient than CBR but may not be as hardware-compatible.
ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3
ffmpeg -i input_file.mp3 -ab 128k output_file.mp3
ffmpeg -i inputfile.mp3 -acodec libmp3lame -b:a 8k -ac 1 -ar 11025 outputfile.mp3
-b:a = audio bitrate
-ar = sample rate
-ac channels = set number of audio channels
- ffmpeg -i "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-RFTYZgBNprg.mp3" -acodec libmp3lame -b:a 112k -ac 2 -ar 44100 "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-112k.mp3"
- ffmpeg -i "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-RFTYZgBNprg.mp3" -ab 112k "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-112k2.mp3"
- ffmpeg -i "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-RFTYZgBNprg.mp3" -b:a 112k -ac 2 -ar 44100 "NON STOP CHRISTMAS MEDLEY VOLUME 1 & 2-112k3.mp3"
explain:
FFmpeg MP3 Encoding Guide
This page describes how to use the external libmp3lame encoding library within ffmpeg to create MP3 audio files (ffmpeg has no native MP3 encoder). See also other codecs you could use, and FFmpeg AAC Encoding Guide if you want AAC instead, and the official documentation.VBR Encoding
Example to encode VBR MP3 audio with ffmpeg using the libmp3lame library:ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3
Control quality with -qscale:a (or the alias -q:a). Values are encoder specific, so for libmp3lame the range is 0-9 where a lower value is a higher quality. 0-3 will normally produce transparent results, 4 (default) should be close to perceptual transparency, and 6 produces an "acceptable" quality. The option -qscale:a is mapped to the -V option in the standalone lame command-line interface tool.LAME Bitrate Overview | |||
---|---|---|---|
lame option | Average kbit/s | Bitrate range kbit/s | ffmpeg option |
-b 320 | 320 | 320 CBR (non VBR) example | -b:a 320k (NB this is 32KB/s, or its max) |
-V 0 | 245 | 220-260 | -q:a 0 (NB this is VBR from 22 to 26 KB/s) |
-V 1 | 225 | 190-250 | -q:a 1 |
-V 2 | 190 | 170-210 | -q:a 2 |
-V 3 | 175 | 150-195 | -q:a 3 |
-V 4 | 165 | 140-185 | -q:a 4 |
-V 5 | 130 | 120-150 | -q:a 5 |
-V 6 | 115 | 100-130 | -q:a 6 |
-V 7 | 100 | 80-120 | -q:a 7 |
-V 8 | 85 | 70-105 | -q:a 8 |
-V 9 | 65 | 45-85 | -q:a 9 |
CBR Encoding
If you need constant bitrate (CBR) MP3 audio, you need to use the -b:a option instead of -qscale:a. Here you can specify the number of bits per second, for example -b:a 256k if you want 256 Kbit/s (25.6 KB/s) audio. Available options are: 8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, or 320 (add a k after each to get that rate). So to get the highest quality setting use -b:a 320k (but see note below).
Note: Using -b:a 320k is generally considered wasteful because:
- -q:a 0 – -q:a 3 will normally produce transparent results.
- MP3 is lossy anyway, so if you really want the highest quality use a lossless format such as FLAC.
ABR Encoding
ABR is something of a mixture between VBR and CBR, see the official documentation for details on use.Troubleshooting
Sometimes the output will consist of fewer bits per second than requested:- With CBR it could be due to the chosen value being in-between allowable settings (it defaults down to the next lower acceptable bitrate).
- With VBR it could be due to the input already in being a lower bitrate than requested, in which case, it basically just re-encodes it at the bitrate of the input.
- Or possibly that the input was CBR, and the VBR aspect is able to reduce bitrate by a considerable amount.
Also see
Download in other formats:
Guidelines for high quality lossy audio encoding
This guide is meant to help people new to encoding lossy audio to use the correct encoders and settings.When should I transcode audio?
Avoid transcoding from a lossy format to the same or another lossy format when possible. Transcode to lossy from the lossless source (if you have it), or just copy the lossy source audio track instead of transcoding.Another option if you have a lossless source is to transcode it to another lossless codec, like flac .
Generation loss
Transcoding from a lossy format like MP3, AAC, Vorbis, Opus, WMA, etc. to the same or different lossy format might degrade the audio quality even if the bitrate stays the same (or higher). This quality degradation might not be audible to you but it might be audible to others.This post on hydrogenaudio.org demonstrates what will happen if you re-encode a file 100 times: http://www.hydrogenaud.io/forums/index.php?showtopic=100067
Copying audio tracks
If the target container format supports the audio codec of the source file then consider just muxing it into the output file without re-encoding. MKV supports virtually any audio codec. This can be achieved by specifying 'copy' as the audio codec.Example:
Transcoding a WebM file (with VP8 video/Vorbis audio) to a MKV file (with H.264 video/unaltered Vorbis audio):
ffmpeg -i someFile.webm -c:a copy -c:v libx264 outFile.mkv
In some cases this might not be possible, because the target device/player doesn't support the codec or the target container format doesn't support the codec. Another reason to transcode might be that the source audio track is too big (it has a higher bitrate than what you want to use in the output file).Audio encoders FFmpeg can use
FFmpeg can encode to a wide variety of lossy audio formats.Here are some popular lossy formats with encoders listed that FFmpeg can use:
Dolby Digital: ac3
Dolby Digital Plus: eac3
MP2: libtwolame, mp2
Windows Media Audio 1: wmav1
Windows Media Audio 2: wmav2
AAC LC: libfdk_aac, aac
HE-AAC: libfdk_aac
Vorbis: libvorbis, vorbis
MP3: libmp3lame, libshine
Opus: libopus
Based on quality produced from high to low:libopus > libvorbis >= libfdk_aac > aac > libmp3lame >= eac3/ac3 > libtwolame > vorbis > mp2 > wmav2/wmav1
For AAC-LC:libfdk_aac > aac
The >= sign means greater or the same quality.This list is just a general guide and there may be cases where a codec listed to the right will perform better than one listed to the left at certain bitrates.
The highest quality internal/native encoder available in FFmpeg without any external libraries is aac.
Please note it is not recommended to use the experimental vorbis for Vorbis encoding; use libvorbis instead.
Please note that wmav1 and wmav2 don't seem to be able to reach transparency at any given bitrate.
Container formats
Only certain audio codecs will be able to fit in your target output file.Container | Audio formats supported |
MKV/MKA | Vorbis, MP2, MP3, LC-AAC, HE-AAC, WMAv1, WMAv2, AC3, eAC3, Opus |
MP4/M4A | MP2, MP3, LC-AAC, HE-AAC, AC3 |
FLV/F4V | MP3, LC-AAC, HE-AAC |
3GP/3G2 | LC-AAC, HE-AAC |
MPG | MP2, MP3 |
PS/TS Stream | MP2, MP3, LC-AAC, HE-AAC, AC3 |
M2TS | AC3, eAC3 |
VOB | MP2, AC3 |
RMVB | Vorbis, HE-AAC |
WebM | Vorbis, Opus |
OGG | Vorbis, Opus |
Recommended minimum bitrates to use
The bitrates listed here assume 2-channel stereo and a sample rate of 44.1kHz or 48kHz. Mono, speech, and quiet audio may require fewer bits.- libopus Usable range >= 80Kbps. Recommended range >= 128Kbps
- libfdk_aac default AAC LC profile. Recommended range >= 128Kbps; see AAC Encoding Guide.
- libfdk_aac -profile:a aac_he_v2 Usable range <= 48Kbps CBR. Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency
- libfdk_aac -profile:a aac_he Usable range >= 48Kbps and <= 80Kbps CBR. Transparency: Does not reach transparency. Use AAC LC instead to achieve transparency
- libvorbis Usable range >= 96Kbps. Recommended range -aq 4 (>= 128Kbps)
- libmp3lame Usable range >= 128Kbps. Recommended range -aq 2 (>= 192Kbps)
- ac3 or eac3 Usable range >= 160Kbps. Recommended range >= 160Kbps
Example of usage:
ffmpeg -i input.wav -c:a libfaac -q:a 330 -cutoff 15000 output.m4a
- aac Usable range >= 32Kbps (depending on profile and audio). Recommended range >= 128Kbps
Example of usage:ffmpeg -i input.wav output.m4a
- libtwolame Usable range >= 192Kbps. Recommended range >= 256Kbps
- mp2 Usable range >= 320Kbps. Recommended range >= 320Kbps
The wmav1/wmav2 encoder does not reach transparency at any bitrate.
The vorbis encoder does not use the bitrate specified in FFmpeg. On some samples it does sound reasonable, but the bitrate is very high.
To calculate the bitrate to use for multi-channel audio: (bitrate for stereo) x (channels / 2).
Example for 5.1(6 channels) Vorbis audio: 128Kbps x (6 / 2) = 384Kbps
When compatibility with hardware players doesn't matter then use libvorbis in a MKV container when libfdk_aac isn't available.
When compatibility with hardware players does matter then use libmp3lame or ac3 in a MP4/MKV container when libfdk_aac isn't available.
Transparency means the encoded audio sounds indistinguishable from the audio in the source file.
Some codecs have a more efficient variable bitrate (VBR) mode which optimizes to a given, constant quality level rather than having variable quality at a given, constant bitrate (CBR). The info above is for CBR. VBR is more efficient than CBR but may not be as hardware-compatible.