Input:
# cat list
video1.mp4
video2.mp4
video3.mp4
video4.mp4
My script:
#!/bin/bash
while IFS= read -r line || [[ -n "$line" ]]; do
echo $line
ffmpeg -i $line -c copy -bsf:v h264_mp4toannexb -f mpegts $line.ts
echo $line
done < "./list";
rm *.ts
Every second iterations, bash reads "ideo2.mp4" instead of "video2.mp4" or "ideo4.mp4" instead of "video4.mp4"
FULL output
+ IFS=
+ read -r line
+ echo video1.mp4
video1.mp4
+ ffmpeg -i video1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts video1.mp4.ts
...
+ echo video1.mp4
video1.mp4
+ IFS=
+ read -r line
+ echo ideo2.mp4
ideo2.mp4
+ ffmpeg -i ideo2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts ideo2.mp4.ts
...
ideo2.mp4: No such file or directory
+ echo ideo2.mp4
ideo2.mp4
+ IFS=
+ read -r line
+ echo video3.mp4
video3.mp4
+ ffmpeg -i video3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts video3.mp4.ts
...
+ echo video3.mp4
video3.mp4
+ IFS=
+ read -r line
+ echo ideo4.mp4
ideo4.mp4
+ ffmpeg -i ideo4.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts ideo4.mp4.ts
...
ideo4.mp4: No such file or directory
+ echo ideo4.mp4
ideo4.mp4
When I comment line "ffmpg..." everything works fine.
Testing on local Ubuntu (bash 4.4.20(1)-release) and on VPS (debian) (bash 4.4.12(1))
What is going on?