Using while loop in a video

4 次查看(过去 30 天)
Hello, My goal is to read a video, than split it to different number of frames, and than make it stop. It still does not work. Please help
vid=VideoReader("video.mp4");
k=200;
while hasFrame(vid)
frame=readFrame(vid);
numberOfFrames = vid.NumFrames;
framesToRead = 1:k: numberOfFrames;
limit=length(framesToRead);
for h = 1:length(framesToRead)
if h<limit
thisFrame = read(vid, framesToRead(h));
else
break
end
end
end
  1 个评论
Eliska Paulikova
Eliska Paulikova 2022-10-25
Well I have a video which has more than 100 000 frames --> So I need to read every 2000 frames. I now I have there the step k=200 but it suppose to be 2000
But still it does not work

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2022-10-25
编辑:KALYAN ACHARJYA 2022-10-25
vid=VideoReader('video.mp4');
frame_num=vid.NumFrames;
frame_format='.jpg';
vid=read(vid);
for i=1:frame_num %Initial Level: Check with less number of frames, e.g.i=1:5
frame_name=num2str(i);
file_name=strcat(frame_name,frame_format);
Vid_frame=vid(:,:,:,i);
imwrite(Vid_frame,file_name);%Save the frame in the current directtory
% Or you can save the frame(images) into specific directory also.
end
It's perfectly working in my system with sample video. Hope it Helps, good wishes!
Kalyan

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by