Ffmpeg | batch convert | make same filename

batchconversion

How would I use ffmpeg to create a batch convert file for sample rate conversion, such as:

$ ffmpeg -i *.wav -ar 22050 *.wav

Take note, that i'm only doing a sample rate conversion, but in the end I want to batch convert all *.wav to 22050 *.wav files all while keeping the same file name for all the files converted.

Best Answer

FFMpeg can't write on the same file while reading from it because it can cause errors.
The only way to do it is to convert into another file and replace the original files.
Or you can convert it to another folder and replace the original folder, it's easier.


For Windows:

mkdir outdir
for %i in (*.bmp) do (
ffmpeg -i %i -ar 22050 outdir\%i
)

Note: Replace %i with %%i when putting it in Windows batch file.

For Linux:

mkdir outdir
for i in *.wav; do
  ffmpeg -i $i -ar 22050 outdir/$i;
done

Now just replace your directory with outdir.


For your case:
If you want it for Counter Strike:GO or HLDJ, then look here. HL requires more settings,
audio must be mono (add -ac 1 flag in FFMpeg) and 16-bit (add -acodec pcm_s16le).
So your FFMpeg command (on Linux) will look like this:

mkdir outdir
for i in *.wav; do
  ffmpeg -i $i -acodec pcm_s16le -ac 1 -ar 22050 outdir/$i;
done
Related Question