Using while loop in a video

조회 수: 3 (최근 30일)
Eliska Paulikova
Eliska Paulikova 2022년 10월 25일
편집: KALYAN ACHARJYA 2022년 10월 25일
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개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by