How can I programmatically display specific frames in a video using Video Viewer?

14 ビュー (過去 30 日間)
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
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 件)

    カテゴリ

    Help Center および File ExchangeAudio and Video Data についてさらに検索

    製品


    リリース

    R2023b

    Community Treasure Hunt

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

    Start Hunting!

    Translated by