how to name the output file same as input file but different extension after video conversion? [duplicate]
Asked Answered
H

2

5

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!

Hypothesis answered 4/3, 2018 at 4:37 Comment(2)
Use suffix removal: Replace "$f".webm with ${f%.mp4}.webm.Monomorphic
See this answer regarding parameter expansion.Gramme
L
11

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
Logjam answered 4/3, 2018 at 5:54 Comment(0)
N
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.

Niggling answered 4/3, 2018 at 4:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.