%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%说明:此程序主要是从指定的视频中读取视频,并且将视频重新写入并且播放
%%用的函数说明:
%mmreader读取视频,get获取视频信息,set设置图片的位置和大小,moive播放视频
%strcut构造结构体,read读取视频信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xyloObj = mmreader('traffic1.avi'); %读取视频
get(xyloObj) %获取视频信息
%%%%%%%%%%%%%%%%read函数的用法
%video = read(obj, 1); % first frame only
%video = read(obj, [1 10]); % first 10 frames
%video = read(obj, Inf); % last frame only
%video = read(obj, [50 Inf]); % frame 50 through end of file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lastFrame = read(xyloObj, inf); %读取最后一帧
nFrames = xyloObj.NumberOfFrames; %求取帧的数目
vidHeight = xyloObj.Height; %帧的高度240
vidWidth = xyloObj.Width ; %帧的宽带320
%Preallocate movie structure. %省略号表示换行,经过验证放到一行去对程序结果你没有影响
%构造结构体类型
mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
'colormap', []);
%%%%%%%%经过验证,将上述省略号删除后,对程序的结果没有影响
%mov(1:nFrames) =struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap',[]);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k); %将xyloObj中的数据存储到mov中
end
% Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight]); %position是figure窗口的位置,是[left, bottom, width, height],针对于screen左下角来做的
% Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);