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
Walter Roberson
2023년 4월 18일
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 ?
Duaa Habib
2023년 4월 18일
답변 (1개)
Cris LaPierre
2023년 4월 18일
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
Duaa Habib
2023년 4월 18일
Cris LaPierre
2023년 4월 18일
Current time. I linked to the description in my original post.
Duaa Habib
2023년 4월 18일
Cris LaPierre
2023년 4월 18일
Perhaps this answer? https://www.mathworks.com/matlabcentral/answers/826115-change-frame-rate-of-video-file?s_tid=ans_recom_leaf
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.
Walter Roberson
2023년 4월 18일
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.
카테고리
도움말 센터 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!