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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Sebastian Heyn
  • 387
  • 3
  • 15
  • What are the contents of `rotatelist_2`? – Wintermute Jan 26 '15 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 – Jonathan Leffler Jan 26 '15 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) – Marian Jan 26 '15 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. http://shellcheck.net/ will do the work of finding bugs of this variety for you. – Charles Duffy Jan 26 '15 at 22:18

1 Answers1

2

Use

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

or

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

to prevent ffmpeg reading from rotatelist_2 via stdin.

Cyrus
  • 84,225
  • 14
  • 89
  • 153