How do I extract frames iteratively?

10 ビュー (過去 30 日間)
Daniel Mendoza Hermosillo
Daniel Mendoza Hermosillo 2022 年 4 月 6 日
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 件のコメント
Daniel Mendoza Hermosillo
Daniel Mendoza Hermosillo 2022 年 4 月 7 日
編集済み: Walter Roberson 2022 年 4 月 7 日
% 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.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 4 月 7 日
% 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 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 7 日
% 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 2022 年 4 月 7 日
Thank you this is what I was looking for

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by