1. 可以用mmreader和 read这两个函数读取视频帧
fileName = 'ntia_wfall-qcif_original.avi'; % .avi必须是无损压缩的. obj = mmreader(fileName); vidFrames = read(obj);% 读取所有的帧数据 numFrames = obj.numberOfFrames;% 帧的总数 for k = 1 : numFrames% 读取数据 mov(k).cdata = vidFrames(:,:,:,k);% mov(k)是一个结构体,mov(k).cdata实际上就是一个有RGB的帧 mov(k).colormap = []; end movie(mov);% 在matlab中播放视频
str='D:\Program Files\MATLAB71\work\1.avi'; info=aviinfo(str); fum=info.NumFrames; for i=1:fum mov=aviread(str,i); I=mov.cdata; J=rgb2gray(I); imwrite(J,strcat('F:\shiyan\work\',int2str(i),'.bmp'),'bmp'); end
videoObj = mmreader('highwayII_raw.avi');%读视频文件 nframes = get(videoObj, 'NumberOfFrames');%获取视频文件帧个数 for k = 1 : nframes currentFrame = read(videoObj, k);%读取第i帧 subplot(1,2,1),imshow(currentFrame); grayFrame = rgb2gray(currentFrame);%灰度化 if(k==1) grayFrame_1 = grayFrame; end difgrayFrame= grayFrame - grayFrame_1;%邻帧差 grayFrame_1 = grayFrame; subplot(1,2,2),imshow(difgrayFrame); end