I want to make sure the transcoding was successful before deleting the original file. I'm quite new to for
loops in BASH shell scripting.
for i in *.mp4; do
ffmpeg -i "$i" -c:v libx265 -crf 39 -c:a aac -b:a 128k -y new-"$i";
done
I want to make sure the transcoding was successful before deleting the original file. I'm quite new to for
loops in BASH shell scripting.
for i in *.mp4; do
ffmpeg -i "$i" -c:v libx265 -crf 39 -c:a aac -b:a 128k -y new-"$i";
done
ffprobe -v error "$filename"
or
ffmpeg -v error -i "$filename" -f null -
will check a media file.
BETTER:
You could just check the ffmpeg exit code status when it completes each file. I do not really see a point to quick scan the entire new file - it either worked or it didn't per ffmeg output and exit status when completed:
for i in *.mp4; do
ffmpeg -i "$i" -c:v libx265 -crf 39 -c:a aac -b:a 128k -y new-"$i";
if [[ $? == 0 ]]; then
printf "FILE OKAY -\t %s \n" $i
else
printf "FILE ERROR -\t %s \n" $i
fi
done
In BASH, $?
holds last executed command status ("exit status"). Normally, if this isn't '0', you had an error running last command. This would seem to be best bet if I understand question correctly.
You could also do it after all the files are produced with something like:
for i in ./*.mp4; do
ffmpeg -v error -i ${i} -f null - 2>/dev/null;
if [[ $? == 0 ]]; then
printf "FILE OKAY -\t %s \n" $i
else
printf "FILE ERROR -\t %s \n" $i
fi
done
Output:
FILE OKAY - ./access.mp4
FILE OKAY - ./another.mp4
FILE ERROR - ./bad.mp4