srthompers
srthompers

Reputation: 169

Matlab thinks an AVI it's written is corrupt

I'm using matlab to interface with a scientific camera using mex, and my matlab program uses VideoWriter() to write the file to disc. The camera is RGB-capable, and if I write the file as such, the video is fine. However, for the current application, I need grayscale images, and so I'm using rgb2gray() to convert it. Unfortunately, when the analysis code tried to read the video file again, I get the error:

Error using VideoReader/init (line 450)
Unable to read the file. The file appears to be corrupt.

and attempting to read the video with VLC confirms it to be corrupt. The only difference in my code between they grayscale and colour versions is the line:

frame = rgb2gray(frame);

My whole writing section of code is:

vid = VideoWriter('testVid.avi');
vid.FrameRate = framerate;
vid.Quality = 100;
open(vid);
for i = 1 : frames;
    %read frame data into variable 'frame'
    frame = rgb2gray(frame);
    writeVideo(vid,frame);
end

I've spent far too long fighting with this, any ideas?

Upvotes: 1

Views: 530

Answers (1)

Daniel
Daniel

Reputation: 36720

You need to close the video object, using close(vid) after writing the last frame.

Upvotes: 3

Related Questions