Video Frame Time Stamps

Version (2.79 KB) by Dave
Retrieve timestamps of individual video frames using ffmpeg.exe


Updated 23 Jan 2017

View License

VIDEOFRAMETS attempts to solve an issue with quantitative video analysis. While
mpeg video is recorded with a fixed framerate, in reality, video frames often
deviate from this value. [I think this is due to delays in the encoder, for
instance if the computer recording video is under excessive load, frames will come
in slower]. If frames often come in a little bit slower than expected (empirical
framerate < nominal framerate), the problem compounds over the course of a video:
if a user assumes a fixed framerate the data at the end of the video will be
greatly mismatched from reality.
This presents a tremendous problem to time locked video analysis. Matlab's
VideoReader offers a practical solution: VideoReader objects contain a property
that identifies/sets the current time in the video. This is generally a practical
solution to the problem (note: when used with the newer .readFrame method rather
than the older .read method). However, this has some limitations:
1: It is often useful to know the number of frames and the corresponding
timestamps at the onset of video analysis (although a rough estimate is
obtainable using the .FrameRate and .Duration properties of VideoReader,
typically adequate for initializing variables).
2: The performance of vision.VideoFileReader is often orders of magnitude
faster than VideoReader (from personal measurements, speed improvements
depend on codec), and seems to work more reliably with a wider set of video
files. However, vision.VideoFileReader offers no strategy for assessing
frame times. Using VideoReader for timing and vision.VideoFileReader for frame
data is impractical because it sacrifices the advantages of using the
vision.VideoFileReader function
3: It may be useful to some users to get timing information only, for instance
if performing video analysis elsewhere.

The times of frames are stored in the MPEG file using presentation timestamps
(PTS; frequently used for alignment of video and auditory streams). While these
are inaccessible to the high level Matlab coder, the tool ffmpeg readily provides
their values, and runs pretty quickly (in testing, 50 seconds for a 20 minute
MPEG file, while VideoReader gets the same information in about 6 minutes).

Cite As

Dave (2023). Video Frame Time Stamps (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes