How to extract a frame every 10 s from the video ?

Hi,
I have a video which runs for 30 minutes at the rate of 60 fps. I need to extract the frame every 10 second. For example: 10s(600th frame),20s(1200th frame),30s(1800th frame) so on..... I looked through the internet I can get the info about how to read, write video and extract frame but did not get the info about exactly what I am looking for. Your help will be appreciated!
Thanks

 Risposta accettata

Stephan
Stephan il 21 Apr 2021
Modificato: Stephan il 21 Apr 2021
In your case the interval to take the first frame after 10 seconds would be:
v = VideoReader('YOUR_FILENAME.mp4');
frames = read(v,[600:600:end]);
The result is a 4D-Array which is the first 3 dimensions having the video frame and the 4th dimension is the time - here 10 seconds

7 Commenti

Link is very useful, but I am getting this error using the code above,
Error:
The end operator must be used within an array index expression.
Error in Spec_Frame (line 3)
frame = read(v,[600:600:end]);
Also would like to know how would I then save that data into the separate folder, for example I read the info and it shows me into the workspace, how would i save images showing into the work space into the folder for further processing.
v = VideoReader('YOUR_FILENAME.mp4');
frames = read(v);
frames = frames(:,:,:,600:600:end);
for k = 1:size(frames,4)
imwrite(frames(:,:,:,k),['C:\YOUR_FOLDER\MyImage_', num2str(k), '.jpg'])
end
Hi, thansk for the quick reply. 2 questions, why did end operator not work for the previous code? and second is the error I am getting this time is that mean data is too big ?
Error:
Error using Movie_Frame (line 38)
Requested 720x1280x3x20259 (52.2GB) array exceeds maximum array size preference. Creation of arrays greater
than this limit may take a long time and cause MATLAB to become unresponsive.
wanted_frames = 600:600:20259;
v = VideoReader('YOUR_FILENAME.mp4');
for k = 1:numel(wanted_frames)
frame = read(v, wanted_frames(k));
imwrite(frame,['C:\YOUR_FOLDER\MyImage_', num2str(k), '.jpg'])
end
Sir could you please help me the writing the code for to divide video into frames for every 2 seconds.The file properties are length:1:46 Frame rate: 29.92 fs Storage:16.7mb
I don't know what this means. Do you want to split up a single video into multiple videos, each having a run time of 2 seconds? Do you want to take the frames for each 2 second long segment and write them out to a folder (with a name that is the start time of that segment)?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by