51

I can convert wav file to pcm

ffmpeg -i file.wav -f s16le -acodec pcm_s16le file.pcm

How can I revert this operation?

1
  • you should be able to use -acodec copy right?
    – rogerdpack
    Apr 14, 2014 at 16:35

4 Answers 4

105

The wav container just adds a simple header to the raw PCM data. The header includes the format, sample rate, and number of channels. Since the raw PCM data does not include this information, you will need to specify it on the command line. Options are specified before the file they apply to, so options before the input file may be used to specify the format of the input file, and options after the input file and before the output file may be used to specify the desired format of the output file. If you want the same bits/sample, sample rate, and number of channels in the output file then you don't need any output options in this case; the wav container format is already indicated by the file extension.

Example to convert raw PCM to WAV:

ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
  • -f s16le … signed 16-bit little endian samples
  • -ar 44.1k … sample rate 44.1kHz
  • -ac 2 … 2 channels (stereo)
  • -i file.pcm … input file
  • file.wav … output file
4
  • 2
    What about reverse(PCM to WAV) operation? Jul 18, 2013 at 9:26
  • 7
    @mustafa.yavuz: This is the PCM-to-WAV-operation.
    – bos
    Mar 2, 2016 at 18:29
  • 3
    @bos, I guess @mustafa.yavuz was asking the reverse(WAV to PCM). Then nothing special, simply ffmpeg -i file.wav file.pcm will do since all information needed to do the conversion is in the header of the wav file.
    – neevek
    Apr 13, 2016 at 9:48
  • I tripped on the -f parameter. Tried to use one value from ffmpeg -sample_fmts. The right values are as on barney's answer.
    – Pablo H
    Apr 6, 2020 at 19:51
15

Be careful with RAW data format

-f u8 is unsigned 8 bit, s16 is signed just in case there are others

 $ ffmpeg -formats | grep PCM
 DE alaw            PCM A-law
 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 mulaw           PCM mu-law
 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 s8              PCM signed 8-bit
 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
 DE u8              PCM unsigned 8-bit
12
ffmpeg -f s16le -ar 8000 -ac 2 -i out.pcm -ar 44100 -ac 2 out.wav
0
-2

The following code should work:

ffmpeg -f s16le -ar 8000 -ac 2 -i out.pcm -ar 44100 -ac 2 out.wav
1
  • 7
    This answer is an identical copy of @olegog's answer above.
    – M.T
    Aug 13, 2019 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.