4

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!

kofhearts
  • 2,845
  • 5
  • 30
  • 65

2 Answers2

6

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
xskxzr
  • 10,946
  • 11
  • 32
  • 70
hch
  • 122
  • 4
3

From what I can tell this link is the answer you're looking for. Though you may not need the part that removes the path since you're simply running this within the folder.

Try:

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

How do I remove the file suffix and path portion from a path string in Bash?

Edit: Added example; After updating I realize someone else gave the same update.

brianweyer
  • 31
  • 5