How read frames within specified time interval exactly from video?
조회 수: 15 (최근 30일)
이전 댓글 표시
Hi, everyone.
In Matlab R2017b, I tried to read video frames within specified time interval in this URL ->(https://jp.mathworks.com/help/matlab/import_export/read-video-files.html?searchHighlight=CurrentTime&s_tid=doc_srchtitle)
However, I could not read frames in exact time. When I tried this, extracted frames is always misaligned about 15 frames from the original video.
Are there any ideas for solving this problem or another way to read frames?
댓글 수: 5
Tohru Kikawada
2018년 2월 13일
편집: Tohru Kikawada
2018년 2월 14일
The code you shared works on my end. Could you please clarify the problem you are facing? Otherwise, it might be a problem depending on the codec which is installed on your end.

vidObj = VideoReader('xylophone.mp4');
s = struct('cdata',zeros(vidObj.Height,vidObj.Width,3,'uint8'),...
'colormap',[]);
k = 1;
currAxes = axes;
while hasFrame(vidObj)
% Acquire the current time
t = vidObj.CurrentTime;
% Acquire the video frame
vidFrame = readFrame(vidObj);
% Needs Computer Vision System Toolbox
vidFrame = insertText(vidFrame,[0 0],num2str(t,'time:% f'),'FontSize',40);
% Capture the video frames at the specified duration
if 0.6 <= t && t <= 0.9
s(k).cdata = vidFrame;
k = k+1;
end
% Show the video frame slowly
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
drawnow limitrate;
pause(1/vidObj.FrameRate);
end
% Display the captured results
frames = cat(4,s.cdata);
figure, montage(frames);
Anna Karchevskaya
2020년 9월 21일
편집: Anna Karchevskaya
2020년 9월 22일
Good day, I used the same code on my video, but I have two questions:
1) Is it possible to reduce numer of frames? I want to get frames for every 150 ms for a specific period of time. I mean, I got the idea, how to do it:
But I cant understand how to implement this code into your?
2) How can I export these frames one by one (for a specific period of time), so I won't get the "montage" - picture in the end. I mean, what should be written in the code in this case?
Thank you
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 オーディオとビデオ에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!