0

I run the following bash script to rotate my mobile phone vids

while read filename ; do
    nf=$(echo $filename |rev | cut -f1 -d '/'|cut -f2- -d '.' |rev)
    echo $nf
    rm -f ffmpeg2pass-0.log
    rm -f rotate/tmp.avi
    ffmpeg -i $filename -c:v libxvid -pass 1 -c:a libmp3lame -qscale:a 4 -vf "transpose=2,transpose=2" "rotate/tmp.avi"
    ffmpeg -i $filename -c:v libxvid -pass 2 -c:a libmp3lame -qscale:a 4 -vf "transpose=2,transpose=2" "rotate/$nf.avi"
done <rotatelist_2

I know there are better ways to do this; I budged this together but I'm figuring out how to do the videos right so the rest don't need to look nice ;-))

However after the first run, the loop unexpectedly ends with no error message. I run similar loops for other things which work pretty well.

The echo is not called again so I guess there's something wrong with the loop itself. The linebreak in the list is a 0x0A, so it should be ok.

4
  • What are the contents of rotatelist_2? Commented Jan 26, 2015 at 21:54
  • 2
    Does any of the commands within the loop read standard input too? If so, it ate the rest of rotatelist_2. It looks like it would have to be ffmpeg that does that, so I don't rate it highly as a possibility. You could use while read -u 3 filename; do ...; done 3<rotatelist_2 and see if that solves the problem. Commented Jan 26, 2015 at 21:59
  • 1
    That ugly second line can be replaced using basename. This assumes the filename extension is always the same, if it isn't, something like ${x%.*} will do (details under Remove matching suffix pattern. in the bash man page) Commented Jan 26, 2015 at 22:11
  • 2
    While we're kibitzing -- lots of bugs here that would be fixed by adding more quotes. "$filename" will deal with spaces, glob characters, etc. within names correctly; bare $filename won't. shellcheck.net will do the work of finding bugs of this variety for you. Commented Jan 26, 2015 at 22:18

1 Answer 1

2

Use

</dev/null ffmpeg ...
</dev/null ffmpeg ... 

or

ffmpeg ... </dev/null
ffmpeg ... </dev/null

to prevent ffmpeg reading from rotatelist_2 via stdin.

Sign up to request clarification or add additional context in comments.

3 Comments

The other approach is to redirect from the file (and then read) on a FD other than stdin.
Yes, Jonathan Leffler's solution is smarter.
That's even better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.