Thursday, November 01, 2007

MATLAB: deal with .avi file

Read the video file and get all the information:
mov = aviread('carslave.avi');
movinfo = aviinfo('carslave.avi')
noframe = movinfo.NumFrames;

Get the first frame and change to image file:
frame1 = aviread('carslave', 1);
img = frame2im(frame1);

frame2im only deals with uint8 format. It doesn't work with some avi files with uint16 data. Mark here and try to find solution later.

Get the image files and play in movie:
for i = 1:100
[X, map] = gray2ind(img, 256); %rgb2ind
mov(i) = im2frame(X, map);

Create avi file:
%aviobj = avifile('test.avi');
aviobj = avifile('test.avi','fps',25,'COMPRESSION','None');
for i = 1:100
[X, map] = gray2ind(img, 256);
rgbimg = ind2rgb(X, map);
aviobj = addframe(aviobj, rgbimg);
aviobj = close(aviobj);

Check this videoIO toolbox

No comments:

Post a Comment