美文网首页
使用 matlab将mp4视频转换成图像帧

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

作者: 小小孩儿的碎碎念 | 来源:发表于2019-12-04 11:57 被阅读0次

使用 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视频转换成图像帧

      本文链接:https://www.haomeiwen.com/subject/punkgctx.html