Written by me@grafxflow
20 May, 2025
0
17
Just incase you have a folder full of video files and want to know if any of them are corrupt you can do it using ffmpeg the following bash script. The script will list all the video files in the folder and loop through them all.
Anybody who edits videos will at some point in their career need to do this!
So for mp4's use the following script and save it as checkVideoErrorsMp4.sh:
#!/bin/bash
for name in *.mp4; do
ffmpeg -v error -i "$name" -f null - > "error $name.log" 2>&1
# Detect if there is and error file and if it's empty
if [ -e "error $name.log" ] && [ ! -s "error $name.log" ]; then
echo "The file 'error $name.log' exists and there are no errors."
elif [ ! -e "error $name.log" ]; then
echo "The file 'error $name.log' does not exist."
else
echo "The file 'error $name.log' exists and there are errors."
fi
done
And in the terminal choose the folder containing the videos then run the script via bash:
cd /videos-folder
bash checkVideoErrorsMp4.sh
And for mkv's use the following script and save it as checkVideoErrorsMkv.sh:
#!/bin/bash
for name in *.mkv; do
ffmpeg -v error -i "$name" -f null - > "error $name.log" 2>&1
# Detect if there is and error file and if it's empty
if [ -e "error $name.log" ] && [ ! -s "error $name.log" ]; then
echo "The file 'error $name.log' exists and there are no errors."
elif [ ! -e "error $name.log" ]; then
echo "The file 'error $name.log' does not exist."
else
echo "The file 'error $name.log' exists and there are errors."
fi
done
And in the terminal choose the folder containing the videos then run the script via bash:
cd /videos-folder
bash checkVideoErrorsMkv.sh
Hope this helps.
30 Dec, 2018
07 Oct, 2016
11 Nov, 2018
I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!
Follow20 May, 2025
11 Jul, 2023
Views: 169,159
Views: 41,774
Views: 39,490
Views: 36,381