Files
wcx_script/checkmp4.sh
2025-10-09 10:55:52 +02:00

48 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# checkmp4.sh <directory>
#
# Verifies all .mp4 files in the given directory ie checks if they are broken or not.
# Prints "OK" or "Not OK" for each file.
# Exit code is 0 if all files are OK, 1 if any are broken.
dir="$1"
if [ -z "$dir" ]; then
echo "Usage: $0 <directory>"
exit 2
fi
if [ ! -d "$dir" ]; then
echo "Not a directory: $dir"
exit 2
fi
bad=0
# loop through mp4 files (non-recursive)
# use `find "$dir" -type f -iname "*.mp4"` if you want recursive
shopt -s nullglob
for file in "$dir"/*.mp4 "$dir"/*.MP4; do
[ -e "$file" ] || continue
# --- Test 1: metadata sanity check ---
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,duration \
-of csv=p=0 "$file" > /dev/null 2>&1
probe_status=$?
# --- Test 2: deep read/decode ---
ffmpeg -v error -xerror -i "$file" -f null - -nostats > /dev/null 2>&1
decode_status=$?
if [ $probe_status -eq 0 ] && [ $decode_status -eq 0 ]; then
echo "OK $file"
else
echo "Not OK $file"
bad=1
fi
done
shopt -u nullglob
exit $bad