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
find /video/folder -iname "*.mp4" > $workingDir/file_list
cat $workingDir/file_list | while read LINE; do
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.