I'm processing a variety of audio files in a bunch of different formats and I'd like to unify their format and configuration using FFMPEG and SoX.
There are two steps to my process:
- Convert the file, whatever it may originally be, to a PCM 16-bit little-endian WAV file:
ffmpeg -i input.wav -c:a pcm_s16le output.wav
- Process the file in Sox to make it conform to the sample rate and channel count that we need:
sox input.wav output.flac channels 2 rate 44.1k
I'd ideally like to pipe these two commands together so as to avoid creating an unnecessary file.
I'm having a lot of trouble actually getting the format to work properly, though.
SoX complains that it needs to explicitly know the format of the incoming audio, which is something that I don't even know at execution time. I know the format of the PCM audio, but I'm not sure the channel count nor of the sample rate of the incoming audio.
Is there a way to pipe these two commands together, or better, to only have to use one tool for the job?
The reason I've used two tools rather than just trying to do it with one:
FFMPEG
- Not sure if there's a way to safely convert a mono audio stream to a stereo audio stream by duplicating the channels. (SoX does this natively.)
- Not sure how to change sample rate. (SoX does this natively.)
- Not sure how to output to FLAC using the best compression rate.
SoX
- Not able to do audio format detection as well as FFMPEG does. If I have a file without an extension, SoX asks me to manually specify the format, which doesn't work at all for my application.
sox output.wav …
?ffmpeg {params} | sox {params}
if possible. I currently useffmpeg
to create a file namedoutput-standardized.wav
and then havesox
use this file to create a file namedoutput-fixed.flac
.