user2783132
user2783132

Reputation: 225

Run a function from while read line

I'm trying to run a function from while read line, the function contains ffmpeg commands to marge two files. but for some reason it's running the first $line and than breaks from loop.

"$filesList" contains three lines. I'm not sure what's wrong, but i can confirm with echo "$OFILE" that opener function runs three times if I comment out the ffmpeg commands, and only once with ffmpeg commands.

opener(){
        OFILE="$1"
        echo "$OFILE"

        ffmpeg -i $opener_path -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
        ffmpeg -i $OFILE -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
        ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc merge_$OFILE

        mv merge_$OFILE $OFILE
        rm intermediate1.ts intermediate2.ts
}


while read line; do
        if [ -e "$line" ]; then
                opener "$line"
        fi
done <<< "$filesList"

Upvotes: 1

Views: 1377

Answers (1)

chepner
chepner

Reputation: 530882

It appears one of the ffmpeg commands is reading from standard input, which consumes the rest of the contents of $filesList before the next call to read. I'm not familiar with ffmpeg, but two possibilities:

  1. Does -i require an argument? Your posted code doesn't set the value of opener_path, so its unquoted expansion would produce an empty string that is discarded by the shell.

  2. How is concat:intermediate1.ts|intermediate2.ts interpreted by ffmpeg? Given the call to rm, it seems to produce a pair of files from an unknown source.

Upvotes: 1

Related Questions