29
9
What command should I use to convert a mp3
file to wav
whose bitrate is variable. Or better how would I know whether that source audio is fixed
bitrate or variable
?
29
9
What command should I use to convert a mp3
file to wav
whose bitrate is variable. Or better how would I know whether that source audio is fixed
bitrate or variable
?
39
You can get some info about the bitrate of your input files by using the ffprobe song.mp3
command. However this only tells you bitrate of the first frame. VBR in MP3 files is usually implemented simply by changing the bitrate for each frame, so whether it's being used can't be determined by just reading the header of first frame. I usually use some other audio file player software to determine whether VBR is being used, as many will display that (Foobar2000 does for example).
When you use lossy output codecs (such as MPEG-1 Layer III or AAC), ffmpeg chooses a default bitrate for the output stream, or a variable bitrate. It depends on the encoder itself.
For lossless codecs, you cannot set a variable bitrate, since each sample takes a predefined number of bits. ffmpeg -i song.mp3 song.wav
will therefore get you a PCM-encoded WAV file with 44,100 Hz sample rate and 16 bits per sample. This results in about 1411 kBit/s for the entire container, likely much, much bigger than the MP3 input file.
If you want a smaller file size for the PCM-encoded WAV file, set a sample format with less bit depth (see -encoders
option for a complete list of them) and/or choose a lower sample rate (-ar 22050
would use 22.05 kHz for example).
Here's an example of doing both:
ffmpeg -i song.mp3 -acodec pcm_u8 -ar 22050 song.wav
14You're probably better off doing ffmpeg -i song.mp3 song.wav
, as that will choose the appropriate bitrate (which is probably 44.1khz). If you're converting to wav, you're probably not wanting to lose further information.. – naught101 – 2015-05-24T12:43:03.373
@naught101 was right, infact it's better to let ffpmeg
to choose the right sampling bitrate according to the song.mp3
input data. In this way the output bitmap wav
file will have the best bitrate. This means btw that the file size will be great, but with on overfitting of the data: Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
– loretoparisi – 2016-04-21T08:59:45.043
1It is fairly safe to assume, the asker's purpose is to burn the resulting WAV-files to an audio CD. The only suitable frequency for that is 44100 Hz, so -ar 44100
is a must even if ffmpeg will automatically use a suitable 16-bit codec. – Mikhail T. – 2017-01-09T02:37:09.037
5If you encode PCM audio in a WAV container, you cannot set the bitrate. That does not make sense. PCM is an uncompressed format — you can't tell it to use more or fewer bits per second. The only way to adjust the size is to use a different sample size (see -sample_fmts
option). -ar 128k
means that the sample rate will be 128,000 Hz, instead of the usual 44,1 or 48 kHz. – slhck – 2013-11-14T18:12:45.760
3
According to @naught101 comment, I would follow this process to detect the best acodec
:
$ ffmpeg -formats | grep PCM
DE f32be PCM 32-bit floating-point big-endian
DE f32le PCM 32-bit floating-point little-endian
DE f64be PCM 64-bit floating-point big-endian
DE f64le PCM 64-bit floating-point little-endian
DE s16be PCM signed 16-bit big-endian
DE s16le PCM signed 16-bit little-endian
DE s24be PCM signed 24-bit big-endian
DE s24le PCM signed 24-bit little-endian
DE s32be PCM signed 32-bit big-endian
DE s32le PCM signed 32-bit little-endian
DE u16be PCM unsigned 16-bit big-endian
DE u16le PCM unsigned 16-bit little-endian
DE u24be PCM unsigned 24-bit big-endian
DE u24le PCM unsigned 24-bit little-endian
DE u32be PCM unsigned 32-bit big-endian
DE u32le PCM unsigned 32-bit little-endian
At this point, consider your platform to choose between big-endian
, little-endian
, the choose bitrate:
$ ffmpeg -i sample.mp3
[mp3 @ 0x7fb33180da00] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'sample.mp3':
Metadata:
title : Saturday
artist : Winterwood
album : Love In The Heart
track : 2/15
TPA : 1/1
encoded_by : iTunes 11.0.1
genre : Country & Folk
date : 1997
Duration: 00:04:27.76, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
We can see that this audio file is a mp3
(this is not obvious, despite of the extension of the input file, just check the bytes) has a bitrate of 128 kb/s
, the codec was s16p
, sampling at 44100 Hz
, so we choose accordingly:
$ ffmpeg -i sample.mp3 -acodec pcm_s16le -ar 44100 sample.wav
Input #0, mp3, from 'sample.mp3':
Metadata:
title : Saturday
artist : Winterwood
album : Love In The Heart
track : 2/15
TPA : 1/1
encoded_by : iTunes 11.0.1
genre : Country & Folk
date : 1997
Duration: 00:04:27.76, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
File 'sample.wav' already exists. Overwrite ? [y/N] y
Output #0, wav, to 'sample.wav':
Metadata:
INAM : Saturday
IART : Winterwood
IPRD : Love In The Heart
IPRT : 2/15
TPA : 1/1
ITCH : iTunes 11.0.1
IGNR : Country & Folk
ICRD : 1997
ISFT : Lavf56.4.101
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc56.1.100 pcm_s16le
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size= 46125kB time=00:04:27.75 bitrate=1411.2kbits/s
video:0kB audio:46125kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000457%
If you are on mac you can that check the audio if it has no white noise
at the beginning / end (when the mp3 original audio has no audio for some msec/sec):
$ afplay sample.wav
and of course you can double check the bitmap:
$ ffmpeg -i sample.wav
Input #0, wav, from 'sample.wav':
Metadata:
artist : Winterwood
date : 1997
genre : Country & Folk
title : Saturday
album : Love In The Heart
track : 2/15
encoder : Lavf56.4.101
encoded_by : iTunes 11.0.1
Duration: 00:04:27.76, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
0
Use ffmpeg to convert the media, first check file specification using ffprobe.
use this command
ffmpeg -i kimberly.wav -acodec pcm_s16le -ar 16000 -ac 1 song.wav
where
-pcm_s16le is codec 16 bit conversion
-ar is sampling rate (16000samples/sec)
-ac no of audio channel
3I don't think the WAV file format supports variable bit rates. Since all MP3 decoders must support it to be standards compliant, you should be able to convert any MP3 file into a fixed-bitrate WAV, although your results will vary depending on the quality of the source MP3 and the fixed-bitrate chosen for the WAV created. Most MP3 playing software provides a way to view the properties of the file being played, so you could use one to see what kind of source files you're dealing with. – martineau – 2013-11-13T13:25:08.590
And what about the command? What do you recommend? – Soham Dasgupta – 2013-11-13T17:27:49.763
Please read martineau's answer again. I corrected a few mistakes. Notably, you cannot set the bitrate for PCM-encoded WAV files. – slhck – 2013-11-14T18:18:53.100