MATLAB Version: 2010a
OS: Windows 7
这段代码可将avi视频中的每一帧画面截取出来,并转存到单独的文件夹中。
PS:下面的是matlab代码。
1 clear;
2 clc;
3
4 % choose a video file
5 [filename, pathname] = uigetfile(\'*.avi\', \'choose a video file\', \'video.avi\', \'Multiselect\', \'on\');
6
7 fprintf(\'filename = %s \npathname = %s \n\n\', filename, pathname);
8
9 if ischar(filename)
10
11 fprintf(\'choose file success.\n\n\');
12
13 video = mmreader([pathname filename]);
14 len = video.NumberOfFrames; % get length of the video
15
16 fprintf(\'length of video : %d \n\n\', len);
17
18 dir=strcat(pathname,strrep(filename,\'.avi\',\'\'),\'\pic\');
19 mkdir(dir); % create folder for saving picture
20 fn=strrep(filename,\'.avi\',\'\');
21
22 for k = 1 : len - 1
23 frame = rgb2gray(read(video, k));
24 imwrite(frame,strcat(dir,\'\\',fn,\'-avi-000\',int2str(k),\'.bmp\'),\'bmp\');
25 end
26
27 end