You are not logged in.
Pages: 1
I have this lovely little script that I whipped up:
#!/bin/bash
OIFS=$IFS
for i in $( ls *.flv ); do
set -- "$i"
IFS="."
declare -a Array=($*)
if [ ! -e ${Array[0]}.mp3 ]; then
ffmpeg -i ${Array[0]}.flv -vn -acodec copy -ar 44100 -ac 2 -ab 1048576 -f mp3 ${Array[0]}.mp3
fi
done
IFS=$OIFS
which looks for any .flv file that has no matching .mp3 file and creates that .mp3 file. It works fine but not for a .flv file with a space in the name.
I tried
ffmpeg -i \"${Array[0]}.flv\" -vn -acodec copy -ar 44100 -ac 2 -ab 1048576 -f mp3 \"${Array[0]}.mp3\"
but that doesn't seem to work.
Can anyone tell me how to get such files to process?
Offline
Offline
Try this one:
if [ ! -e "${Array[0]}.mp3" ]; then
ffmpeg -i "${Array[0]}.flv" -vn -acodec copy -ar 44100 -ac 2 -ab 1048576 -f mp3 "${Array[0]}.mp3"
Website: andrwe.org
Offline
Andrwe, I had tried that before also. The " characters don't come through in the final command so it doesn't help.
falconindy, you're a bit of a genius, eh? Took me a half hour to figure out that syntax and you replaced my code with a few lines. Well you skipped the IF. Here is the code that works, using your trick:
#!/bin/bash
for i in *.flv; do
if [ ! -e "${i%.*}.mp3" ]; then
ffmpeg -i "${i%.*}.flv" -vn -acodec copy -ar 44100 -ac 2 -ab 1048576 -f mp3 "${i%.*}.mp3"
fi
done
Thank you. That's pretty cool.
Offline
Aha. I've had a long day -- I think I glanced at the if/then and didn't think it was necessary. Now that I look at it again, you're right to leave it in.
You should probably assign the base filename to a variable rather than calling the string manip 3 times.
Just an FYI: quotes in shell commands are for functional purposes only -- the actual quotes won't (and shouldn't) appear in the parsed command. If they did, the program executed would be looking for an argument that had a literal quote in it. Simply put:
$ touch "foo bar"
$ ls "foo bar"
foo bar
$ ls \"foo bar\"
ls: cannot access "foo: No such file or directory
ls: cannot access bar": No such file or directory
Last edited by falconindy (2010-05-12 22:59:24)
Offline
Thanks.
Offline
#!/bin/bash
for i in *.flv; do
[[ ! -e ${i%.*}.mp3 ]] && ffmpeg -i "${i%.*}.flv" -vn -acodec copy -ar 44100 -ac 2 -ab 1048576 -f mp3 "${i%.*}.mp3"
done
Offline
Pages: 1