How do I extract frames iteratively?

10 visualizaciones (últimos 30 días)
Daniel Mendoza Hermosillo
Daniel Mendoza Hermosillo el 6 de Abr. de 2022
Comentada: Daniel Mendoza Hermosillo el 7 de Abr. de 2022
So far I have been able to trim the video and went from 4007 frames to 1509 frames, from those frames I only want to get every 3rd frame starting from the first. Currently I only know how to trim the video and to check how much frames the video has not much else.
  1 comentario
Daniel Mendoza Hermosillo
Daniel Mendoza Hermosillo el 7 de Abr. de 2022
Editada: Walter Roberson el 7 de Abr. de 2022
% Import video file
obj = VideoReader('D:\Spring 2022\MARS Capstone\Trimmed Videos\Reef 1\GH010063.MP4');
vid = read(obj);
% Read the total number of frames
frames = obj.NumFrames;
% File format of the frames to be saved
ST = ' .jpg';
% Reading and writing the frames
for x = 1 : frames
% Converting integers to string
Sx = num2str(x);
% Concatening 2 string
Strc = strcat(Sx, ST);
vid = vid(:, :, :, x);
% Exporting the frames
imwrite(vid, Strc);
end
this is a code i found online that helps me write the frames into images that I can use later but it stops because it needs 23.2 GB storage to run, so I wanted to reduce the number of frames that I pick up from this code.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Abr. de 2022
% Import video file
obj = VideoReader('D:\Spring 2022\MARS Capstone\Trimmed Videos\Reef 1\GH010063.MP4');
% File format of the frames to be saved
ST = ' .jpg';
% Reading and writing the frames
i = 1;
while hasframe(obj)
% Converting integers to string
Sx = num2str(x);
% Concatening 2 string
Strc = strcat(Sx, ST);
vid = readframe(obj);
% Exporting the frames
imwrite(vid, Strc);
i = i + 1;
end
  3 comentarios
Walter Roberson
Walter Roberson el 7 de Abr. de 2022
% Import video file
obj = VideoReader('D:\Spring 2022\MARS Capstone\Trimmed Videos\Reef 1\GH010063.MP4');
% File format of the frames to be saved
ST = ' .jpg';
% Reading and writing the frames
x = 0;
while hasframe(obj)
vid = readframe(obj);
x = x + 1;
if mod(x, 3) ~= 1; continue; end
% Converting integers to string
Sx = num2str(x);
% Concatening 2 string
Strc = strcat(Sx, ST);
% Exporting the frames
imwrite(vid, Strc);
end
It is also possible to ask to read() a particular frame by frame index, but I suspect this code would be faster.
Daniel Mendoza Hermosillo
Daniel Mendoza Hermosillo el 7 de Abr. de 2022
Thank you this is what I was looking for

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by