FFmpeg - convert WebM/Opus to WAV or FLAC in single step?

I want to create WAV and FLAC audio files from WebM files with Opus audio streams, and I want to do so without further degrading the audio. I am currently using a 2-step process as follows (WAV example show):

ffmpeg -i "file.webm" -vn -acodec copy "file.opus"
ffmpeg -i "file.opus" "file.wav"

Is it possible to do this in one step? If so, does it vary for WAV vs. FLAC?

I have tried the following, but it leads to a different file size so I presume that it is re-encoding in some intermediary format before creating the WAV file (leading to audio degradation that the "-acodec copy" flag avoids):

ffmpeg -i "file.webm" -vn "file.wav"

Solution 1:

maybe a bit late but still some answers :

someone pointed a solution in a comment and to shorten it you can SKIP :

 -ac 2

(default setting is stipulated in the documentation as this "For output streams it is set by default to the number of input audio channels", so not needed in your case you don't want to re-map audio channels)

 -f wav

(if you name your output file with a .wav extension ffmpeg will by default use wav format also specified in the documentation "The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases." it's the case here for your output .wav file)

ffmpeg -i "file.webm" -vn "file.wav"

by default this will re-encode your opus stream to pcm_s16le this refers to PCM signed 16-bit little-endian (-vn ignores video track and album cover)

you can choose another format -f, this page sure can help you if you need to have a specific audio format in your .wav : https://trac.ffmpeg.org/wiki/audio%20types

this one liner is the simplest cause all you do with your first command is copying the opus stream into another container (same data stream with tags added (writing library tag updated) then convert it to pcm (.wav)

while the one liner do exactly the same to your audio and even faster by "skipping re-encapsulate into .opus" step and just transcoding your opus stream to a pcm stream.

The differences in size that you observed may have been caused by changes in metadata not the audio stream itself :)