how can I process certien frames from a video?

I uploaded a 5 minutes video and I want to process only the first 2 minutes, then the seconed 2 minute and so on...
should I use a windo or frame size or how can I do that?

댓글 수: 2

Are you streaming the video from a source, such as youtube? Possibly one using H.264 ? Or do you have a local copy of the video file that you can read from? Or is it at least stored on a network drive (even if that does mean OneDrive) where it can be accessed as a file ?
yes i have a local copy of the video

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 4월 18일

0 개 추천

How are you reading in your frames? Are you using VideoReader?
I haven't tried it, but following the examples on the linked page, I would look into using the CurrentTime property as my while loop conditional instead of hasFrame.
Maybe something like this?
v = VideoReader('xylophone.mp4');
while v.CurrentTime < 120
frame = readFrame(v);
end

댓글 수: 5

what does 120 represents here
Current time. I linked to the description in my original post.
I see, thanks.
do you know how can I write code to take one frame every nth of frames until the number of frames ends, for example if the video has 60 frames per second and I want to make it 30 frames per second
Otherwise, you could use code similar to the above, and have two calls to readFrame in each loop, and just ignore the data from one of them.
You could also figure out the number of frames in your video (Duration and FrameRate properties) and then use a loop to load the specific frames you want using read with the frame specified.
v = VideoReader('xylophone.mp4');
every_n = 2;
seconds_to_process = 120;
fc = 0;
while hasFrame(v) && v.CurrentTime < seconds_to_process
frame = readFrame(v);
fc = fc + 1;
if mod(fc, every_n) == 0
do something with frame
end
end
It is possible to ask to read specific frames. For example you could ask to
read(v, 2:2:119)
and get those frames in a block. However it is generally faster not to ask for specific frames by number, at least not if you are asking one-by-one.

댓글을 달려면 로그인하십시오.

카테고리

질문:

2023년 4월 18일

댓글:

2023년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by