Read specific frames between time interval in a video

4 ビュー (過去 30 日間)
S
S 2016 年 6 月 15 日
編集済み: S 2016 年 6 月 15 日
Hello, I want to read specific frames from a video, with a constant sampling rate (specifically one frame every 210 frames) between time1 and time2 points in a video. The problem I am facing is with read, which I cannot use after setting CurrentTime.
I have this code :
NumberOfFrames=1;
input.CurrentTime = 66;
while input.CurrentTime<486
sampling_factor=210;
jump=35;
thisFrame.cdata = read(input, (NumberOfFrames-1)*sampling_factor+jump);
disp((NumberOfFrames-1)*sampling_factor+jump);
end
which crashes because I cannot call read after setting currenttime (that is the error I get).
The workaround would be to first trim the video with
input.CurrentTime = 66;
k = 1;
while input.CurrentTime <= 486
newvid=readFrame(input);
k = k+1;
end
and then extract the frames, but this is not an "elegant" solution and would create memory issues. Does anybody have any advice on how to approach this?
P.S Moreover this :
while input.CurrentTime>66 && input.CurrentTime<486
sampling_factor=210;
jump=35;
nFrames = floor(totalFrames/sampling_factor);
thisFrame.cdata = read(input, (NumberOfFrames-1)*sampling_factor+jump);
does not work at all, the loop never begins :S
UPDATE
The solution to this is to move f rom working with frames, to working with time. So here's the code that worked :
time_interval=7 ;
while input.CurrentTime<486
thisFrame.cdata = readFrame(input);
imwrite(thisFrame.cdata,foldername,'png');
end
input.CurrentTime=floor(input.CurrentTime+time_interval);
disp(input.CurrentTime);
end
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 6 月 15 日
I am not sure why you would say it would create memory issues? You are not required to store all of the frames you read.
The read() method is going to go away, so you should be rewriting in terms of readFrame()
I do not know why read() is going away; I speculate it might have something to do with variable frame-rate videos, or possibly something to do with streaming videos.
S
S 2016 年 6 月 15 日
FYI I think I found a solution. Instead of working with frame number, I am trying to work with time slot. So I am now writing something like this:
input.CurrentTime=x;
while input.CurrentTime<y
thisFrame.cdata=readFrame(input)
input.CurrentTime=input.CurrentTime+time_interval;
end
now I only have to figure out the correct time interval :D

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by