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.


# in case we're using a fork of ffmpeg like ubuntu, us 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
    if [ -f "$OUTP" -o -f "$OUTP_OK" ] ; then
        echo Skipping "$i"
        echo Checking "$i"...
        "$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"

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.



avconv vs ffmpeg