imageVideoFrames
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Video/Audio/PDF
Introduced first in SolidGeometry 3.2, Creation date: 2016-12-28, Last change: 2025-09-14
extracts images from a video file
See Also: imageVideoFrames
, imageVideoTitle
, imageVideoTextPage
, imageVideoEndtitle
, imageVideoWrite
, videoCopyFrames
, videoCopyCutMovies
Example Illustration
Syntax
[Ic,vr]=imageVideoFrames(xy,[ptime])
Input Parameter
xy: | | filename of the video file |
ptime: | | array or cells of time; default is 0 |
Output Parameter
Ic: | | cells of images |
vr: | | video reader object |
Examples
imageVideoFrames('/Users/lueth/Desktop/newfile.avi',[2,3]) % works
imageVideoFrames('/Users/lueth/Desktop/newfile.avi',{2,3}) % works also
Copyright 2016-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, imageVideoFrames, extracts specific frames from a video file based on given time points.
Input Parameters
- xy: The filename of the video file. It should be a string representing the path to the video.
- ptime: An array or cell array of time points (in seconds) from which frames are to be extracted. The default value is 0 if not provided.
Output Results
- Ic: A cell array containing the extracted images (frames) from the video.
- vr: A video reader object used to read the video file.
Algorithm Steps
- Initialize
ptime to 0. If a second argument is provided and is not empty, set ptime to this argument.
- If
ptime is not a cell array, convert it to one.
- Check if the file specified by
xy exists. If it does, create a VideoReader object vr for the file.
- Retrieve the video's width, height, duration, and frame rate using the
VideoReader object.
- Calculate the number of time points
n.
- If the maximum time point exceeds the video's duration, issue a warning.
- Sort the time points and convert them to frame indices by multiplying by the frame rate and adding 1.
- Initialize a cell array
Ic to store the extracted frames.
- Initialize frame counter
f and index k.
- While there are frames left in the video and
k is less than or equal to n:
- Increment the frame counter
f.
- Read the next frame from the video.
- If the current frame number matches the desired frame index, store the frame in
Ic and increment k.
- If no output arguments are specified, display each extracted frame using
imshow and pause for 1 second between displays.
Algorithm explaination created using ChatGPT on 2025-08-19 07:29. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21