views:

825

answers:

2

Hello all,

I was kindly helped a few minutes ago by a user named Juliano and the script works fine but it just baffles me why it continues to work when I press enter, if I don't it just sits there untill I have to keep pressing enter. I thought that was the job of the for loop?

    #!/bin/bash
    TIMEFORMAT=%6R
    for file in /home/test/videos/* ; do
     #for loop 2
     for (( i = 0; i < 10; i++ )); do
      #for loop 3
      for ext in avi mpg wmv mov; do
          base="${file##*/}"
          elapsed=$({ time ffmpeg -i "$file" -ar 44100 "${file%/*}/done/${base%.*}.$ext" &>/dev/null; } 2>&1)
          echo "$file $i $ext took $elapsed seconds"
        done
      done
    done

Also can I swap for loops 2 and 3?

Thanks all

Update

How can I also make use of the variable "i" in the for loop so that it concatinates at the end of the file. Is this correct:

${file%/}/done/${base%.}$i.$ext

Thank you for anymore help.

+3  A: 

I suspect that the ffmpeg program is what's waiting for the keypress at the end of the process. You might be able to send it a keypress, like:

echo -e \\n | time ffmpeg ...

which might echo a new line "into" the standard input of the ffmpeg program.

And yes, you can swap loop #2 and #3.

scraimer
You are correct that has made it continue automatically - But do I have to replace the "time" with "echo -e \\n" as I need the time. Sorry for being a noob, but how do i get both. Thanks.
Abs
echo -e \\n | time ffmpeg ...
camh
You can use both : `echo -e \\n | time ffmpeg ...`
rampion
Omg, sorry for being so retarded. Also how can I concatenate the variable "i" to the filename? Please see my update.
Abs
oops, sorry. type. will fix.
scraimer
+3  A: 

I already answered in the other question. It was ffmpeg asking you to overwrite the output file. Giving unique names (with $i in the filename) and passing -y to ffmpeg solves the problem.

Juliano
I made use of your exact new script with one location change and all it does not is just output but not actually execute the ffmpeg command?
Abs
It is hard to say the reason without more information. Run "bash -x script.sh" to see what bash is running. I fixed the script, again.
Juliano
Yes, it is working after you latest change! :) Thank you.
Abs