how to name the output file same as input file but different extension after video conversion?

kofhearts picture kofhearts · Mar 4, 2018 · Viewed 9k times · Source

I am using this line to batch convert mp4 files to webm files. For all mp4 files i need the output files to be of same name but .webm extension. For example if i have video1.mp4 and video2.mp4 then after conversion i need two files i.e video1.webm and video2.webm. How can i achieve this using bash script?

for f in *.mp4; do ffmpeg -i "$f" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "$f".webm;  done

The above code will change the output file to video1.mp4.webm. Thanks!

Answer

hch picture hch · Mar 4, 2018

Try this ...

for f in *.mp4; 
do 
    ffmpeg -i "$f" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "${f%.mp4}".webm;  
done