1

I wrote a small script that converts HQ video to LQ:

ls video/hq | cut -d. -f1 | while read line ; do
  HQ=./video/hq/$line.mp4
  LQ=./video/lq/$line.mp4
  ffmpeg -i $HQ -crf 40 $LQ
done;

When I run ls video/hq | cut -d. f1 I get back:

1502460615677
1502461135975
1502461292963
1502461373947
1502461493936
1502461782119

But when running the conversion script only 1502460615677 is processed.

If I replace the line with ffmpeg with echo $line echo runs for all but with ffmpeg it only runs for one.

Anyone know why ffmpeg changes how this runs?

  • Aside from parsing ls I don't see a problem. Add set -x to see what commands are actually running. – glenn jackman Aug 11 '17 at 15:11
  • @glennjackman before ffmpeg runs I get +read line and then the script ends so no new information. – Philip Kirkbride Aug 11 '17 at 15:16
  • @glennjackman strange if I switch my ffmpeg command for echo it works fine. It seems like ffmpeg breaks out of the loop or something(?) – Philip Kirkbride Aug 11 '17 at 15:22
2

Apparently ffmpeg reads from standard input, which interferes with the read command. So I'm directing to /dev/null

ls video/hq | cut -d. -f1 | while read line ; do
  HQ=./video/hq/$line.mp4
  LQ=./video/lq/$line.mp4
  ffmpeg -i $HQ -crf 40 $LQ < /dev/null
done;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.