Hey ARWA,
While there isn’t a direct function that can achieve the functionality you are looking for, we can use a combination of VideoReader and implay() function in Video Viewer to achieve this.
The approach is to use the VideoReader object, which itself is lightweight, to track and read the frames of the video we need. Once we have the frames, we can pass them to implay(), along with the frame rate to play it smoothly.
The following code illustrates this appoach:
% Specify the path to your AVI file
filename = 'sample.avi';
% Create a VideoReader object
video = VideoReader(filename);
% Define the range of frames you want to read
startFrame = 30;
endFrame = 90;
% Calculate the total number of frames to read
numFramesToRead = endFrame - startFrame + 1;
% Preallocate a structure to store the frames
frames(numFramesToRead) = struct('cdata', [], 'colormap', []);
% Set the starting frame
video.CurrentTime = (startFrame-1) / video.FrameRate;
% Loop through and read the frames
for k = 1:numFramesToRead
% readFrame automatically updates CurrentTime to the next frame
frames(k).cdata = readFrame(video);
end
% Play the frames as a video
implay(frames,video.FrameRate);
If the number of frames to be read is substantial, then you can replace for loop with parfor loop, which is parallel for loops to parallelise the reading of frames. You can refer to parfor loop documentation below:
Refer to the following for VideoReader documentation:
Refer to the following for implay() function’s documentation: