Reputation: 7349
I'm doing some image processing on several thousand small .avi files. A small subset of the files appear to be damaged.
One type of damage seems to be a particular frame of the video that can't be read in. I added a try-catch block for this and it works well.
Another type of damage, however, is, according to VLC, "Broken or missing AVI Index". When VideoReader attempts to open files with this type of damage it crashes Matlab completely with the error, "MATLAB has encountered an internal problem and needs to close." And details message, "Segmentation violation detected at Wed Apr ..."
So my question is, is there any way to error check/skip videos that would cause this crash?
Upvotes: 1
Views: 532
Reputation: 32144
You may use ffmpeg for checking the integrity of video file.
See: How can I check the integrity of a video file (avi, mpeg, mp4…)?
Download static build of ffmpeg
, and put ffmpeg.exe
in your working directory.
Execute ffmpeg
within Matlab using system
command, and check the return status.
If status is not zero, the video file is corrupted.
You may also parse the output error message for finer logic.
Here is a code sample:
filename = 'input.avi';
if (isunix)
[status, cmdout] = system(['ffmpeg.exe -v error -i ', filename, ' -f null - 2']);
else
[status, cmdout] = system(['ffmpeg.exe -v error -i ', filename, ' -f null - 2>&1']);
end
if (status ~= 0)
%Dispaly cmdout if file is damaged.
disp([filename, ' is corrupted. Error: ', cmdout]);
end
Upvotes: 2