Skip to content

Instantly share code, notes, and snippets.

@okhlybov
Created April 9, 2025 10:34
Show Gist options
  • Save okhlybov/570347e7086411958899abe22bfe6554 to your computer and use it in GitHub Desktop.
Save okhlybov/570347e7086411958899abe22bfe6554 to your computer and use it in GitHub Desktop.
Recursively scan & perform integrity check on video files
#!/bin/bash
# Recursively scan current directory for video files and check their integrity
# Output names of broken files to the standard error channel
clean() {
rm "$log"
}
trap clean INT
while IFS= read -r -d $'\0' file <&3; do
log="$file.log"
if [ ! -f "$log" ]; then
echo -n "$file"
ffmpeg -v error -i "$file" -f null - 2> "$log"
if [ -s "$log" ]; then
echo " [BAD]"
else
echo
fi
fi
done 3< <(find -type f -regextype egrep -iregex '.*\.(avi|mov|mkv|mp4|3gp|mpg|mpeg)$' -print0)
while IFS= read -r -d $'\0' log <&3; do
file=$(echo $log | sed 's/.log$//')
if [ -s "$log" ]; then
>&2 echo "$file"
fi
rm "$log"
done 3< <(find -type f -regextype egrep -regex '.*\.log$' -print0)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment