SoX resample and convert

audio, ffmpeg, sox

Solution

SoX determines the files type by looking at its extension. To adjust the rate of the output file, add the `-r` option to the output files formatting options. From the manual synopsis:

sox 
  [global-options]
  [format-options] infile1 [[format-options] infile2] ...
  [format-options] outfile
  [effect [effect-options]] ...

Items in brackets are optional, `...` means zero or more of the previous item.

Here is an example of how to perform both actions with one command:

sox master.wav -r 22050 out.ogg

Alternatively, you could add the rate manipulation to the effects chain:

sox master.wav out.ogg rate 22050

Problem

I am trying to figure out how to combine two commands in SoX. My master file is 44.1 kHz. I first want to resample this file to 22 kHz and then convert it to mp3/opus/ogg. How can I do this with a single command?

Original source