Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

VideoReader

Read video files

Description

VideoReader objects are associated with files containing video data.

VideoReader supports the following file formats.

Platforms

File Formats

All Platforms

AVI, including uncompressed, indexed, grayscale, and Motion JPEG-encoded video (.avi)
Motion JPEG 2000 (.mj2)

All Windows®

MPEG-1 (.mpg)
Windows Media® Video (.wmv, .asf, .asx)
Any format supported by Microsoft® DirectShow®

Windows 7 or later

MPEG-4, including H.264 encoded video (.mp4, .m4v)
Apple QuickTime Movie (.mov)
Any format supported by Microsoft Media Foundation

Macintosh

Most formats supported by QuickTime Player, including:
MPEG-1 (.mpg)
MPEG-4, including H.264 encoded video (.mp4, .m4v)
Apple QuickTime Movie (.mov)
3GPP
3GPP2
AVCHD
DV

Note: For OS X Yosemite (Version 10.10) and later, MPEG-4/H.264 files written using VideoWriter, play correctly, but display an inexact frame rate.

Linux®

Any format supported by your installed plug-ins for GStreamer 1.0 or higher, as listed on http://gstreamer.freedesktop.org/documentation/plugins.html, including Ogg Theora (.ogg).

Use dot notation to view or modify a particular property of a VideoReader object. For example, this command finds the value of the Duration property of the VideoReader object, v.

D = v.Duration;

Properties are read only, except CurrentTime, Tag, and UserData. Modify the CurrentTime property to begin reading from a particular time in the video file.

Creation

Create VideoReader objects using the VideoReader function.

Properties

expand all

This property is read-only.

Bits per pixel of the video data, specified as a numeric scalar.

Data Types: double

Timestamp of the video frame to read, specified as a numeric scalar. Specify the timestamp in seconds from the start of the video file. The value of CurrentTime can be between zero and the duration of the video.

Example: 120.54

Data Types: double

This property is read-only.

Length of the file in seconds, specified as a numeric scalar.

Data Types: double

This property is read-only.

Number of video frames per second, specified as a numeric scalar. For variable-frame rate video, FrameRate is the average frame rate.

Note: For OS X Yosemite (Version 10.10) and later, MPEG-4/H.264 files written using VideoWriter, play correctly, but display an inexact frame rate.

Data Types: double

This property is read-only.

Height of the video frame in pixels, specified as a numeric scalar.

Data Types: double

This property is read-only.

File name, specified as a character vector.

Data Types: char

This property is read-only.

Note

NumberOfFrames is not recommended. Use CurrentTime instead.

Number of frames in the video stream, specified as a numeric scalar˙.

Data Types: double

This property is read-only.

Full path to the video file associated with the reader object, specified as a character vector.

Data Types: char

Generic text field

Data Types: char

User-defined data. UserData can be any data type.

This property is read-only.

MATLAB representation of the video format, specified as a character vector.

For all file types except Motion JPEG 2000 files, VideoFormat is one of the following.

Video Format

Value of VideoFormat

AVI or MPEG-4 files with RGB24 video

'RGB24'

AVI files with indexed video

'Indexed'

AVI files with grayscale video

'Grayscale'

For Motion JPEG 2000 files, VideoFormat is one of the following.

Format of Image Data

Value of VideoFormat

Single-band uint8'Mono8'
Single-band int8'Mono8 Signed'
Single-band uint16'Mono16'
Single-band int16'Mono16 Signed'
Three-banded uint8'RGB24'
Three-banded int8'RGB24 Signed'
Three-banded uint16'RGB48'
Three-banded int16'RGB48 Signed'

This property is read-only.

Width of the video frame in pixels, specified as a numeric scalar.

Data Types: double

Object Functions

readRead video frame data from file
VideoReader.getFileFormatsFile formats that VideoReader supports
readFrameRead video frame from video file
hasFrameDetermine if frame is available to read

Examples

expand all

Create a VideoReader object for the example movie file, xylophone.mp4.

v = VideoReader('xylophone.mp4');

Read all video frames.

while hasFrame(v)
    video = readFrame(v);
end
whos video
  Name         Size                Bytes  Class    Attributes

  video      240x320x3            230400  uint8              

Create an object to read the sample file, xylophone.mp4.

v = VideoReader('xylophone.mp4');

Specify that reading should begin 2.5 seconds from the beginning of the video.

v.CurrentTime = 2.5;

Create an axes. Then, read video frames until no more frames are available to read.

currAxes = axes;
while hasFrame(v)
    vidFrame = readFrame(v);
    image(vidFrame, 'Parent', currAxes);
    currAxes.Visible = 'off';
    pause(1/v.FrameRate);
end

Introduced in R2010b

Was this topic helpful?