使用matlab间隔一定时间提取视频一帧的图片

1.编译环境

1.1matlab 2017a

1.2window 10

2.主要流程

找一个视频,matlab格式支持mp4,下面以mp4格式为例。(VideoReader supports these file formats:MPEG-1 (.mpg)
Windows Media® Video (.wmv.asf.asx))

具体操作如下:

%clc;
%clear all;
%close all;
VideoAd = VideoReader('F:\Video\Video001.mp4');%输入视频位置
numFrames = VideoAd.NumberOfFrames;% 帧的总数
videoF=VideoAd.FrameRate;%FrameRate 视频采集速率
videoD=VideoAd.Duration;  %Duration  时间
numname=6;%the length of image name
nz = strcat('%0',num2str(numname),'d');
T=1*videoF;%提取帧数间隔,这里设定每1秒提取一一帧
i=1;
 for k = 1 :T: numFrames%     
     numframe = read(VideoAd,k);%读取第几帧
     num=sprintf(nz,i);   %i为保存图片的序号
     i=i+1;
     imwrite(numframe,strcat('F:\VideoDivided_image\001\',num,'.png'),'png');  
     % 保存帧,
     %位置:F:\PeopleTrainingTest_2018.7.25\Test_divide\
 end

Guess you like

Origin blog.csdn.net/qq_42263796/article/details/81518498