Read specific frames between time interval in a video
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 15 Giu 2016
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!