bash: How can executing an external command confuse a while (read lines from file) loop?
Hi,
I have a set of corrupted .mp4 videos and I wrote a bash script to fix them using ffmpeg. Fortunately, only the container is corrupted, and the streams are OK. While fixing, I would like to add titles that are read from a .m3u playlist. The script reads the .m3u file line by line, ignores empty lines and the leading #EXTM3U, and then it depends on the line content: If the line contains "EXTINF:", the title is extracted from that line, remembered, and used for the next line that contains a file name. With that information, ffmpeg is executed. No one alters the input .m3u file. The problem is: After the first time ffmpeg is really executed, the lines read from the .m3u are incomplete, trimmed or whatever. If I comment out the line executing ffmpeg, the file is parsed as expected. This is a shortened version of the .m3u playlist: Code:
#EXTM3U And this is the script (whith ffmpeg commented out): Code:
#!/bin/bash This is the expected output that I only can achieve with ffmpeg commented out: Code:
================================================================================ Code:
================================================================================ Code:
#EXTINF:2913,02 Das Leben soll nicht enden Code:
oll nicht enden What did I miss ? Regards, Markus |
Instead of commenting-out the ffmpeg line, echo it, capture the output.
|
If the invoked command reads from stdin, that is going to absorb some of the input. I'm not sure why ffmpeg would be doing that, but just redirect its stdin from /dev/null:
Code:
ffmpeg ... <dev/null |
Whow, that's it !
Looks like ffmpeg indeed reads from stdin. Redirecting as you suggested is the solution. Thank you very much. |
Two comments.
Code:
done < <(cat "$INPUTFILE") Code:
done < "$INPUTFILE" Code:
while read INPUT_LINE <&3 |
Also, ffmpeg has the option -nostdin to prevent it reading from stdin.
|
All times are GMT -5. The time now is 05:21 PM. |