Skip to content

Instantly share code, notes, and snippets.

@ThomasLobker
Last active March 31, 2019 09:06
Show Gist options
  • Save ThomasLobker/45bb2ec8dcc950c3954b0c2c67b6a01a to your computer and use it in GitHub Desktop.
Save ThomasLobker/45bb2ec8dcc950c3954b0c2c67b6a01a to your computer and use it in GitHub Desktop.
Test media files with ffmpeg and echo all broken files to stderr
#!/bin/bash
# Usage:
# ./testmedia.sh 2>~/broken_files
# Make a temporary file
TEMP=`mktemp`
# Find all media files in current directory
find -type f -name '*.mkv' -o -name '*.avi' > "${TEMP}"
# Go through all files
while read file; do
echo -n "${file} "
# Count the errors with ffmpeg
ERRORS=$(ffmpeg -nostdin -v error -i "${file}" -map 0:1 -f null /dev/null 2>&1 | wc -l)
echo "[${ERRORS} errors]"
# If we have any errors then remove the file
if [ ${ERRORS} -ne 0 ]; then
echo "This file contains errors: ${file}"
(>&2 echo "${file}")
fi
done < "${TEMP}"
# Clean up temporary file
rm "${TEMP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment