Scanning for Bad Media

The only reliable way that I've found (without an exhaustive search) to to actually read through the media files with avconv and note any issues.  This means using a script like the below.

#!/bin/bash

# in case we're using a fork of ffmpeg like ubuntu, us avconv
FFMPEG="/usr/bin/avconv"

# enable spaces in file names with IFS, and find any of the popular extentions
IFS=$(echo -en "\n\b")
LIST=`find  -type f -regex '\(.*avi$\|.*mp4$\|.*m4v$\|.*mkv\)'`

# output to a temp file, and rename as we progress to OK status 
for i in $LIST; do
    TMP_OUTP="$i.tmp"
    OUTP="$i.txt"
    OUTP_OK="$i.txt.ok"    
    if [ -f "$OUTP" -o -f "$OUTP_OK" ] ; then
        echo Skipping "$i"
    else
        echo Checking "$i"...
        RESULT="bad"
        "$FFMPEG" -y -i "$i" -c:v copy -c:a copy -f null - 2> "$TMP_OUTP"
        mv "$TMP_OUTP" "$OUTP"
        RESULT=`grep -v \(Invalid\ data|error\ reading\) "$OUTP"`
        if [ -z "$RESULT" ] ; then
            mv "$OUTP" "$OUTP_OK"
        fi
    fi
done


Note: For speed reasons, I'm simply copying the streams rather than re-encoding as this is much faster. While this may not actually catch subtle errors in the files, we really don't care that much as it's video and a brief blip is overlooked easily.

If you have a problem in your file, you're usually left with .tmp file. Check these first.



Links

Script
http://606u.dir.bg/avicheck/

avconv vs ffmpeg
http://askubuntu.com/questions/432542/is-ffmpeg-missing-from-the-official-repositories-in-14-04

Comments