Using while loop in a video

2 Ansichten (letzte 30 Tage)
Eliska Paulikova
Eliska Paulikova am 25 Okt. 2022
Bearbeitet: KALYAN ACHARJYA am 25 Okt. 2022
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 Kommentar
Eliska Paulikova
Eliska Paulikova am 25 Okt. 2022
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 25 Okt. 2022
Bearbeitet: KALYAN ACHARJYA am 25 Okt. 2022
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

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by