Using while loop in a video

2 visualizaciones (últimos 30 días)
Eliska Paulikova
Eliska Paulikova el 25 de Oct. de 2022
Editada: KALYAN ACHARJYA el 25 de Oct. de 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 comentario
Eliska Paulikova
Eliska Paulikova el 25 de Oct. de 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

Iniciar sesión para comentar.

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 25 de Oct. de 2022
Editada: KALYAN ACHARJYA el 25 de Oct. de 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

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by