Reading in only specific video frames with readFrame
조회 수: 36 (최근 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!