FFmpeg script skips files

I wrote a shell script to convert many video files and save them with something added to the file name. The script works, but it seems to accidentally skip files and many of them.

When I re-run the script, it will convert the files that it skipped before. How can I make it stop skipping files?

workingDir=/home/user/Videos

# get list of files to convert
find /video/folder -iname "*.mp4" > $workingDir/file_list

# convert files
cat $workingDir/file_list | while read LINE; do
    # FFmpeg often cuts off the beginning of this line
    echo "$(dirname "$LINE")/$(basename "$LINE")"
    if /usr/bin/ffmpeg -n -loglevel panic -v quiet -stats -i "$LINE" \
        -c:v libx264 -vf scale="trunc(oh*a/2)*2:320" \
        -pix_fmt yuv420p -preset:v slow -profile:v main -tune:v animation -crf 23 \
        "$(dirname "$LINE")/$(basename "$LINE" \.mp4)"_reencoded.mp4 2>/dev/null; then
            echo "Success: $(dirname "$LINE")/$(basename "$LINE")" >> $workingDir/results
    else
        echo "Failed:  $(dirname "$LINE")/$(basename "$LINE")" >> $workingDir/results
    fi
done

One problem is that FFmpeg is interfering with the script. The output of FFmpeg often disables the start of the next command, even if the output is not displayed. This is illustrated by an echo line before the if statement, which is often interrupted. But even for lines that are not cut off, most of them will be skipped for no apparent reason.

+4
1

ffmpeg stdin, , while read. stdin ffmpeg, < /dev/null

+2

Source: https://habr.com/ru/post/1536600/


All Articles