Check the integrity of batch video files

4

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

  

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

    
asked by anonymous 15.02.2016 / 21:02

1 answer

5

Given that there is no previous HASH (when you were sure of the file state) you need to use a Third Party program FFMPEG and a script executed via Powershell that automates the execution of checking the video files of 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
}
  • In the script I determine the addresses of the folder where the videos are, where the FFMPEG executable is and where the LOG file will be created with the errors of each video
  • I select files based on my needs (videos with extension .mp4 and .mkv )
  • For each file I run FFMPEG passing some control parameters like how verbose the verification should be.
  •   

    Notes:

         
    • Verification is frame by frame as soon as errors are per frame.

    •   
    • It was organized so that the errors printed below the file name. (there may be no error, or there may be several errors   in each frame which generates a huge Log file).

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

    •   
    • I've added a different + # + # + string at the beginning of each file path to make the search easier.

        

    Test Data:

    4 files were tested:

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

    Test time:

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

    Log file size: 19 MB

        
    15.02.2016 / 21:02