Reading in only specific video frames with readFrame
35 次查看(过去 30 天)
显示 更早的评论
Is there any way to read in only specified frames from a video using readFrame? It is possible using VideoReader.read, which accepts an "index" argument to specify which frames are to be read:
video = read(v,index)
But readFrame doesn't have the same option. The read function is being deprecated in a future release, and I would like to ensure that the code that I am writing will continue to work as long as possible into the future. Is this functionality being lost?
The code will potentially need to handle very large video files, so efficiency is important here - I can't just read in every single frame and discard the ones that are not required.
2 个评论
Swarooph
2016-8-9
The same documentation says VideoReader will replace this functionality. You can try using that. Although it does not seem to have the ability to read a particular frame #, it does have the ability to specify CurrentTime of frame and read between intervals.
回答(2 个)
Patrick Feaster
2017-9-1
I ran into the same issue. The solution I came up with, presuming a constant frame rate, is to detect the video frame rate and then divide the desired frame index number, minus 1, by it. Thus, if you want frame index number 10 and your frame rate is 30 fps, set (10-1)/30 as the current time before using readFrame. Frame index number 1 comes out as (1-1)/30 = current time 0. The following function "readindex" can also substitute for "read" with an index specified and should continue to work after "read" is deprecated, with minimal alteration to existing code. Again, this would only work with a constant frame rate.
function outputFrame=readindex(videoSource,frameNumber)
info=get(videoSource);
videoSource.CurrentTime=(frameNumber-1)/info.FrameRate;
outputFrame=readFrame(videoSource);
3 个评论
Iris Hagoort
2017-1-3
Have you already found the solution? I also want to change my code so that it will stay functional in the future. I have build a GUI with a scroller, you can open the movie and use the scroller to go to the desired frame. Are there any other solutions?
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!