Check the integrity of batch video files

Question:

How to check automatically and customizable via Shell/Programming Language the integrity ( Incomplete/Corrupted file) of video files ( .avi , .mp4 , .mkv among others)?

NOTE: Having as a limiting factor the lack of a previous HASH of the files.

Answer:

Since there is no previous HASH (when you were sure of the file's status) it is necessary to use a Third Party FFMPEG program and a script executed via Powershell that automates the execution of checking the video files in a certain folder:

Script:

$logPath = "C:\Users\User\projeto1\error.log"
$videosFolder = "C:\Users\User\videos"
$ffmpegPath = "C:\ffmpeg\bin\ffmpeg.exe"
$arquivos = Get-ChildItem -path $videosFolder | 
    Where-Object {
        ($_.extension -eq ".mp4" -or $_.extension -eq ".mkv")
    }
foreach($item in $arquivos){
    "+#+#+ " + $item.FullName >> $logPath
    &$ffmpegPath -v error -i $item.FullName -f null 2 >> $logPath 2>&1
}
  1. In the script I determine the addresses of the folder where the videos are, where the FFMPEG executable is and where the LOG file with the errors of each video will be created
  2. I select the files based on my needs (only videos with .mp4 and .mkv extensions)
  3. For each file I run FFMPEG passing some control parameters like how verbose the check should be.

Grades:

  • Checking is frame by frame so errors are frame by frame.

  • It has been arranged so that errors are printed below the filename. (There may be no errors at all, or there may be several errors in each frame which generate a huge Log file).

  • NEVER let errors be displayed on standard output, always leave them to be stored in the Log file.

  • Added a +#+#+ differentiated string to the beginning of each file path to make searching easier.

Test Data:

4 files were tested:

  • 2 Perfects (11MB each)
  • 1 Incomplete (Revised from Bittorrent before the end (still partially reproducible)) (55 MB)
  • 1 Corrupted (I opened the file in Notepad++ and added random characters) (11 MB)

Test time:

  • Displaying Log File Error Messages: 17 Seconds
  • Displaying Error Messages in Powershell Console: 14 Minutes

Log file size: 19 MB

Scroll to Top