How can I programmatically display specific frames in a video using Video Viewer?
조회 수: 14 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2024년 1월 24일
답변: MathWorks Support Team
2024년 1월 25일
I am using MATLAB's Video Viewer app to play videos, and I want to display some selected frames. Specifically, I have a vector containing specific frame indices that I wish to display in sequence, with a pause between each. Currently, the app only provides a manual option to jump to frames using an icon. Is there a method to achieve this programmatically?
채택된 답변
MathWorks Support Team
2024년 1월 24일
Currently, the Video Viewer app does not provide a built-in programmatic interface for controlling playback or displaying specific frames. However, you can use MATLAB functions directly to achieve a similar outcome.
As a workaround, you can use the "VideoReader" object to access frames and then display them using the "imshow" function. Below is an example of how to display a sequence of frames from a video with a pause of 1 second between each frame:
% Create a VideoReader object to read the video file
v = VideoReader('xylophone_video.mp4');
% Vector of frame numbers you want to display
frameIndices = [1, 25, 50, 75, 100];
% Loop through the frame indices
for i = 1:length(frameIndices)
% Set the current time of the video reader object
frameIndex = frameIndices(i);
if frameIndex >= 1 && frameIndex <= v.NumFrames
% Get the timestamp of video frame to read
v.CurrentTime = (frameIndex-1) / v.FrameRate;
% Read the frame at the specified time
frame = readFrame(v);
% Display the frame
imshow(frame);
title(['Frame index: ' num2str(frameIndex)]);
% You can apply a fixed pause duration
pause(1); % Pauses for 1 second
else
disp(['Frame number ' num2str(frameIndex) ' is out of range.']);
end
end
For more details about "VideoReader", "readFrame", and "writeVideo", please refer to the following links:
VideoReader:
readFrame:
writeVideo:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!