Last active
August 29, 2015 14:17
-
-
Save samy/47e1dd55bccffab23d85 to your computer and use it in GitHub Desktop.
How to detect truncated MP3 files
This file contains hidden or 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
# Retrieve MP3s list | |
find . -type f -iname "*.mp3" -print0 | while IFS= read -r -d $'\0' line; do | |
# Use sox to extract a MP3 which ends at 0 seconds of the current file | |
sox "$line" temp.mp3 reverse trim 0 reverse | |
# We retrieve original file and copy durations, as integers | |
ORIGINALDURATION=`sox --i -D "$line"` | |
ORIGINALDURATION=`printf %.0f $ORIGINALDURATION` | |
COPYDURATION=`sox --i -D temp.mp3` | |
COPYDURATION=`printf %.0f $COPYDURATION` | |
# A comparison is made between the two values | |
DELTA=` expr $ORIGINALDURATION - $COPYDURATION` | |
if [ $DELTA -gt 10 ] | |
then | |
# If the diff is more than 10 seconds, we rename the file | |
echo 'ERROR : '.$line | |
linenew=`echo "$line" | sed 's/.mp3/.fail/'` | |
mv "$line" "$linenew" | |
rm temp.mp3 | |
else | |
echo 'OK : '.$line | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment