So, I'm using a script I've made to convert videos to the webm format. A certain program calls the script, sending %f which is the full, absolute file name of the video, like this:
converter.sh %f
where %f has two possible extensions, .avi or .mpg.
# /bin/bash
ffmpeg -i $1 `dirname $1``basename $1 avi`webm && rm $1
It currently works perfectly when $1 contains a .avi file, because basename removes the .avi extension. When $1 ends with .mpg instead, the result is .mpgwebm.
How can I modify that script to be able to receive those two possible different formats?
Resuming: If $1 is /somedir/video.avi, the script should do:
ffmpeg -i /somedir/video.avi /somedir/video.webm
And if $1 is /somedir/video.mpg, the script should do:
ffmpeg -i /somedir/video.mpg /somedir/video.webm
I know this might be fool for some people, but I'm kind of new with the bash.
$(…)– Stéphane Gimenez Aug 15 '11 at 03:58*.avi.webmor*.mpg.webmbecausebasenamedoesn't remove the extension unless you specify it after. – Tomas Aug 15 '11 at 04:01sedis a headache. – Tomas Aug 15 '11 at 04:11"$1"instead of just$1? – Tomas Aug 15 '11 at 04:19dirname,basenameand not to use directly `ffmpeg -i "$1" "${1%.*}.webm" && rm "$1" – enzotib Aug 15 '11 at 08:17D=$(dirname "$1")will change all multispace sequences to a single space, without quotes around$(). – enzotib Aug 15 '11 at 08:29