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

 missing image of imageVideoFrames(xy,ptime)

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

Output Results

Algorithm Steps

  1. Initialize ptime to 0. If a second argument is provided and is not empty, set ptime to this argument.
  2. If ptime is not a cell array, convert it to one.
  3. Check if the file specified by xy exists. If it does, create a VideoReader object vr for the file.
  4. Retrieve the video's width, height, duration, and frame rate using the VideoReader object.
  5. Calculate the number of time points n.
  6. If the maximum time point exceeds the video's duration, issue a warning.
  7. Sort the time points and convert them to frame indices by multiplying by the frame rate and adding 1.
  8. Initialize a cell array Ic to store the extracted frames.
  9. Initialize frame counter f and index k.
  10. While there are frames left in the video and k is less than or equal to n:
  11. 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