I'm writing a Bash script in which I read a file line by line ( well, <(find /home/user/ -iname "*.MP4")
to be exact ) , and for each line I execute ffmpeg
, so I'm doing something like this:
while read -r line; do
ffmpeg -i "$line" [ MORE OPTIONS ... ]
done < <(find /home/user/ -iname "*.MP4")
Though, for some reason, only the first line is being processed successfuly.
Any idea why my code ignores all other lines ?
That's a frequent problem which is caused by the special behavior of
ffmpeg
(also happens withssh
).Quoted from Bash FAQ 89 which handles your case almost exactly:
TL;DR :
There are two main options:
Adding a
</dev/null
at the end offfmpeg
's line ( i.e.ffmpeg -i "$line" [ MORE OPTIONS ] ... </dev/null
) will fix the issue and will makeffmpeg
behave as expected.Let
read
read from a File Descriptor which is unlikely to be used by a random program: