Package: bash
Version: 5.3.3(1)-release

Architecture: Debian GNU/Linux forky/sid x86_64 Linux

Problem:  When ffmpeg is present it consumes from fd0 the first character, instead of "time" --> "ime". When you will remove ffmpg command line, "time" appears normally in all cases.

The root cause is a *file descriptor collision*: the loop reads from stdin (fd 0), and FFmpeg, even when given an input file, can internally access or peek at stdin. This can consume bytes from the input stream *before Bash reads them*, resulting in truncated lines. Bash variables themselves are safe; the issue arises because the *input stream (stdin) is not isolated* from child processes. Using a separate file descriptor for reading the file (e.g., |exec 3< file; read -r LINE <&3|) fully isolates the loop from FFmpeg and resolves the problem.


sed -i '/^$/d' frm.txt;
sed -i 's/\x0//g' frm.txt;

while IFS="" read -r LINE; do
       printf '[%s]\n' "$LINE" | od -c


ffmpeg -loglevel error -y -ss "$timepos_formatted" -i "$vid_scr" \
    -frames:v 1 -q:v 1 "$output_dir/${vid_scr}_${frame_padded}_${timepos_formatted}.bmp" \
    >/dev/null 2>&1
done < frm.txt

frm.txt

"time_pos=8.5442222222222, estimated_frame=256
time_pos=10.677244444444, estimated_frame=320
time_pos=13.576933333333, estimated_frame=407
time_pos=17.276422222222, estimated_frame=518
time_pos=26.308555555556, estimated_frame=789
time_pos=39.239966666667, estimated_frame=1177
time_pos=41.173044444444, estimated_frame=1235
time_pos=52.371522222222, estimated_frame=1571
time_pos=66.436244444444, estimated_frame=1993
time_pos=70.169055555556, estimated_frame=2105"

Reply via email to