How can I check the integrity of an avi file and repair it automatically in Linux?

try using mencoder (the encoding part of mplayer) like this:

mencoder -idx problemfile.avi -ovc copy -oac copy -o reindexedfile.avi

(via http://www.kahunaburger.com/2010/01/30/fixing-an-avi-index-with-mencoder/)


Force index

mencoder -forceidx input.avi -o output.avi -oac copy -ovc copy  

Copy all

mencoder -ovc copy -oac copy input.file -o output.file  

Also see https://stackoverflow.com/questions/894903/how-can-i-validate-a-video-file-from-a-script