Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
2  
I 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 Nov 13 '13 at 13:25
    
And what about the command? What do you recommend? – Soham Dasgupta Nov 13 '13 at 17:27
    
Please read martineau's answer again. I corrected a few mistakes. Notably, you cannot set the bitrate for PCM-encoded WAV files. – slhck Nov 14 '13 at 18:18
up vote 8 down vote accepted

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 bitrate, since each sample will take 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
share|improve this answer
2  
If 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 Nov 14 '13 at 18:12
    
@slhck: Thanks for the corrections. – martineau Nov 14 '13 at 20:38
3  
You'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 May 24 '15 at 12:43
    
@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 Apr 21 at 8:59

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
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .