So, I've been researching how to convert all WebM videos to MP4 in a directory. I've looked for about half an hour for results, but unfortunately, Google isn't being my best friend. I found a simple command using ffmpeg to convert a WebM to MP4 in the terminal:

ffmpeg -i video.webm video.mp4

This is useful, but I don't want to do this several times when I have 30+ of these in the same directory. Is there a way to do all of it easy with a script?


You can do this using a shellscript:

for fname in *webm
  do
   ffmpeg -i $fname $(echo $fname | sed "s/webm/mp4/")
done

for fname in *webm is a for loop, where the elements that is iterated over is expanded from *webm, which will match all files ending in .webm

ffmpeg -i $fname $(echo $fname | sed "s/webm/mp4/") runs the command for each of the fname's that we aquired for the loop. $fname will expand to the current name. $(echo $fname | sed "s/webm/mp4/") uses the stream editor to rewrite webm to mp4, thus providing the correct filename for the output for ffmpeg.