6

I need to convert a flac file to a wav file without changing sample rate and bit depth. As far as I know changing these properties may distort the audio, so how do i specify them not to be changed?

Also, is there any way to prevent metadata to be written to the output file?

Edit: Apparently this is an XY Problem, I'm sorry, I'm new here. My problem is that I don't want to install flac on my OS X, because I'm trying to sandbox everything I use, so I need a single executable file, such as ffmpeg. I'll try @slhck's suggestion and check whether sample rate and bit depth change.

Edit: ffmpeg only preserves sample rate. Bit depth needs to be set manually.

  • Why do you want to use ffmpeg for the task? This sounds like a XY problem to me. – user Apr 28 '14 at 09:39
  • @MichaelKjörling Not sure, I personally use ffmpeg for everything, even if there's a flac CLI tool, or an x264 CLI encoder, etc. It's not unreasonable to assume that someone would want to use ffmpeg even if there are "native" tools. – slhck Apr 28 '14 at 09:50
  • @slhck I agree with the point you're making, but in this case I see nothing in the question to indicate why a non-ffmpeg solution wouldn't meet the OP's needs ("convert flac to wav without changing sample rate and bit depth"). The question isn't even explicit that using ffmpeg is necessary; it's only implicit in the question title. I think asking for the reason for the mention of ffmpeg is reasonable. – user Apr 28 '14 at 09:58
  • Here is a solution to convert FLAC to WAV from stackoverflow. –  Jun 20 '14 at 04:04

2 Answers2

11

ffmpeg will not change sample rate unless you tell it to (or the output codec does not support it, but then it will most probably fail). So this should be enough:

ffmpeg -i input.flac output.wav

ffmepg will however not preserve bit depth and default to 16-bit encoding, so if your input is 24 bit, you have to use:

ffmpeg -i input.flac -c:a pcm_s24le output.wav

As for removing metadata, see Strip metadata from all formats with FFmpeg -- you basically only add the -map_metadata -1 option.

slhck
  • 228,104
  • Is this in any way inferior to flac -d flacfile.flac? – Rajib Apr 28 '14 at 09:36
  • 1
    @Rajib Not that I'm aware of, no. But I haven't tested it, so I can't give an authoritative answer here. – slhck Apr 28 '14 at 09:50
  • 1
    Is this really true? It seems to preserve the sample rate but converts 24-bit flac to 16-bit PCM (in WAV). – awy Feb 21 '20 at 16:06
  • @awy You are right. Not sure if that's a regression. – slhck Feb 24 '20 at 08:44
  • @slhck could you please let me know why you chose pcm_s24le and not pcm_s24be? – theeranitp May 29 '22 at 13:29
  • 1
    @theeranitp A large majority of audio files use little-endian encoding. Any reason you need big-endian encoding? – slhck May 29 '22 at 18:07
  • I agree with other commenters. I don't think this works anymore. I'm getting multiple errors. It will go to 16-bit WAV, but no other. I even get errors about channel layout: "Decoder requires channel layout to be set". – Sawtaytoes Jan 22 '24 at 01:13
6

While it does not use ffmpeg as you indicate in the title that you want to do, to convert a FLAC file to .wav you can simply pass it through flac using the --decode (-d) switch.

flac --decode input.flac will produce input.wav as output, containing the same audio data.

You can add --no-keep-foreign-metadata to make flac throw away any non-audio data in the input. (It is the opposite of --keep-foreign-metadata Save/restore WAVE or AIFF non-audio chunks.)

user
  • 29,910