How can I check the integrity of a video file (avi, mpeg, mp4...)?

Solution 1:

You can use a feature in ffmpeg video converter: if you will specify it to recode video to nothing it will just read input file and report any errors that will appear. This is very fast process because video frames are just being read, checked and silently dropped.

Example command line: (for Linux)

ffmpeg -v error -i file.avi -f null - 2>error.log

-v error means a certain level of verbosity (to show some errors that are normally hidden because they don't affect playability a much).

You will get a full error log with some generic information about file ffmpeg will output, so this will probably require your attention, through filters can be written to perform batch check of similar files.

FFmpeg is also available for Windows here. The command line will be almost identical with an exception of stderr redirect:

ffmpeg.exe -v error -i file.avi -f null - >error.log 2>&1

Solution 2:

I liked idea of using ffmpeg -f null above, but I'd actually like to automate process of using that output. In particular, common scenario I have with my music video collection is that I have few clips which have same resolution, and I'd like to diff verification logs for those files to remove ones broken the most.

Unfortunately, ffmpeg so far doesn't have a way to disable its interactive mode, which outputs noise for this case of usage. I ended up hacking simple wrapper script to do filtering:

#!/usr/bin/env python
import sys
import os
import re

t = os.popen('ffmpeg -v 5 -i "%s" -f null - 2>&1' % sys.argv[1]).read()
t = re.sub(r"frame=.+?\r", "", t)
t = re.sub(r"\[(.+?) @ 0x.+?\]", "[\\1]", t)
print t

Example output:

[mpeg1video]ac-tex damaged at 21 17
[mpeg1video]Warning MVs not available
[mpeg1video]concealing 22 DC, 22 AC, 22 MV errors
[mpeg1video]Warning MVs not available
[mpeg1video]concealing 22 DC, 22 AC, 22 MV errors
[mpeg1video]ac-tex damaged at 13 9

Solution 3:

For windows, You can 'batch' check integrity for videos on current folder and all subfolders with this bat file:

checkvideo.bat

@echo off

set "filtro=%1"
if [%filtro%]==[] (
    set "filtro=*.mp4"
    )

for /R %%a in (%filtro%) do call :doWork "%%a"

    PAUSE
    exit /B

:doWork
    C:\ffmpeg\bin\ffmpeg.exe -v error -i %1 -f null - > "%~1.log" 2>&1
    

Use:

checkvideo.bat [filter]

If you don't give one filter, will get '*.mp4'.

Samples: checkvideo.bat checkvideo.bat *.avi

Setup: Download FFmpeg for Windows from here: https://ffmpeg.zeranoe.com/builds/ and unzip them Change C:\ffmpeg\bin\ in the bat file for the path where you have unzipped ffmpeg Put checkvideo.bat on a folder included in the Path or add his folder to Path environment variable

UPDATE: As of September 18,2020, the above link is no longer valid so Windows users can download FFmpeg form here or here