Last active
March 31, 2019 09:06
-
-
Save ThomasLobker/45bb2ec8dcc950c3954b0c2c67b6a01a to your computer and use it in GitHub Desktop.
Test media files with ffmpeg and echo all broken files to stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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