使用 matlab将mp4视频转换成图像帧

使用 matlab将mp4视频转换成图像帧

clear;
lc;
% choose a video file
[filename, pathname] = uigetfile('*.mp4', 'choose a video file', 'video.mp4', 'Multiselect', 'on');
fprintf('filename = %s \npathname = %s \n\n', filename, pathname);
if ischar(filename)
   fprintf('choose file success.\n\n');
   video = VideoReader([pathname filename]);
   len = video.NumberOfFrames; % get length of the video
   fprintf('length of video : %d \n\n', len);
   dir=strcat(pathname,strrep(filename,'.avi',''),'\pic');
   mkdir(dir); % create folder for saving picture
   fn=strrep(filename,'.mp4','');
   for k = 1 : len - 1
       frame = rgb2gray(read(video, k));
       imwrite(frame,strcat(dir,'\',fn,'-mp4-000',int2str(k),'.bmp'),'bmp');
   end
end

你可能感兴趣的:(使用 matlab将mp4视频转换成图像帧)