Read Video Files Read All Frames in Video File This example shows how to read and store data from all frames in a video file, display one frame, and then play all frames at the video's frame rate. Construct a VideoReader object associated with the sample file, xylophone.mp4. vidObj = VideoReader('xylophone.mp4');

Determine the height and width of the frames. vidHeight = vidObj.Height; vidWidth = vidObj.Width;

Create a MATLAB® movie structure array, s. s = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...     'colormap',[]);

Read one frame at a time using readFrame until the end of the file is reached. Append data from each video frame to the structure array. k = 1; while hasFrame(vidObj)     s(k).cdata = readFrame(vidObj);     k = k+1; end

Get information about the movie structure array, s. whos s

  Name      Size                Bytes  Class     Attributes   s         1x141            32503552  struct    s is a 1­by­141 structure array, containing data from the 141 frames in the video file. Display the fifth frame stored in s. image(s(5).cdata)

Resize the current figure and axes based on the video's width and height. Then, play the movie once at the video's frame rate using the movie function. set(gcf,'position',[150 150 vidObj.Width vidObj.Height]); set(gca,'units','pixels'); set(gca,'position',[0 0 vidObj.Width vidObj.Height]); movie(s,1,vidObj.FrameRate);

Close the figure. close

Read All Frames Beginning at Specified Time Read part of a video file starting 0.5 second from the beginning of the file. Construct a VideoReader object associated with the sample file, 'xylophone.mp4'.

vidObj = VideoReader('xylophone.mp4');

Specify that reading should begin 0.5 second from the beginning of the file by setting theCurrentTime property. vidObj.CurrentTime = 0.5;

Create an axes to display the video. Then, read video frames until the end of the file is reached. currAxes = axes; while hasFrame(vidObj)     vidFrame = readFrame(vidObj);     image(vidFrame, 'Parent', currAxes);     currAxes.Visible = 'off';     pause(1/vidObj.FrameRate); end

Read Video Frames Within Specified Time Interval Read part of a video file from 0.6 to 0.9 second. Construct a VideoReader object associated with the sample file, 'xylophone.mp4'. vidObj = VideoReader('xylophone.mp4');

Specify that reading should begin 0.6 second from the beginning of the file by setting theCurrentTime property. vidObj.CurrentTime = 0.6;

Read one frame at a time until the CurrentTime reaches 0.9 second. Append data from each video frame to the structure array, s. k = 1; while vidObj.CurrentTime <= 0.9     s(k).cdata = readFrame(vidObj);     k = k+1; end

View the number of frames in s.

whos s

  Name      Size                Bytes  Class     Attributes   s         1x141            32503552  struct              

s is a 1­by­141 structure array because readFrame read 141 frames. View the CurrentTime property of the VideoReader object. vidObj.CurrentTime

ans =     0.9333

The CurrentTime property is now greater than 0.9.

Troubleshooting: Cannot Read Last Frame of Video File The hasFrame method might return logical 1 (true) when the value of the CurrentTimeproperty is equal to the value of the Duration property. This is due to a limitation in the underlying APIs used. Avoid seeking to the last frame in a video file by setting the CurrentTime property to a value close to the Duration value. For some files, this operation returns an error indicating that the end­of­file has been reached, even though the CurrentTime value is less than the Durationvalue. This typically occurs if the file duration is larger than the duration of the video stream, and there is no video available to read near the end of the file. Do not use the Duration property to limit the reading of data from a video file. It is best to read data until the file reports that there are no more frames available to read. That is, use thehasFrame method to check whether there is a frame available to read.

See Also mmfileinfo | movie | VideoReader

More About Supported Video File Formats

Read Video Files - MATLAB & Simulink.pdf

Read Video Files - MATLAB & Simulink.pdf. Read Video Files - MATLAB & Simulink.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Read Video ...

341KB Sizes 5 Downloads 163 Views

Recommend Documents

Create object to read video files - MATLAB VideoReader.pdf ...
Page 3 of 32. Page 3 of 32. Create object to read video files - MATLAB VideoReader.pdf. Create object to read video files - MATLAB VideoReader.pdf. Open.

Create object to write video files - MATLAB VideoWriter.pdf ...
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Create object to ...

Read video frame data from file - MATLAB readc.pdf
Read video frame data from file - MATLAB readc.pdf. Read video frame data from file - MATLAB readc.pdf. Open. Extract. Open with. Sign In. Main menu.

Read video frame data from file - MATLAB read.pdf
Read video frame data from file - MATLAB read.pdf. Read video frame data from file - MATLAB read.pdf. Open. Extract. Open with. Sign In. Main menu.

Export to Video - MATLAB & Simulink.pdf
Export to Video - MATLAB & Simulink.pdf. Export to Video - MATLAB & Simulink.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Export to Video ...

Write video files - MATLAB.pdf
Write video files - MATLAB.pdf. Write video files - MATLAB.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Write video files - MATLAB.pdf.

Download Web Page and Files - MATLAB & Simulink.pdf
Download Web Page and Files - MATLAB & Simulink.pdf. Download Web Page and Files - MATLAB & Simulink.pdf. Open. Extract. Open with. Sign In.

Face Detection and Tracking Using Live Video Acquisition - MATLAB ...
Face Detection and Tracking Using Live Video Acquisition - MATLAB & Simulink Example.pdf. Face Detection and Tracking Using Live Video Acquisition ...

MATLAB Implementation of Modulator for Video Signals - IJEECS
Research Scholar, VISVESVARAYA TECHNOLOGICAL UNIVERSITY. Belgaum, Karnataka, ... QPSK modulator for video signals using Matlab. The. Input video ...

Read MATLAB for Engineers: Global Edition - Read Unlimited eBooks
Read MATLAB for Engineers: Global Edition - Read Unlimited eBooks

matlab
The MathWorks, Inc. 3 Apple Hill Drive. Natick, MA 01760-2098. For contact information about worldwide offices, see the MathWorks Web site. Neural Network ...

MATLAB BOOK.pdf
Page 1. Whoops! There was a problem loading more pages. Retrying... MATLAB BOOK.pdf. MATLAB BOOK.pdf. Open. Extract. Open with. Sign In. Main menu.

MATLAB Primer
The plain TEX source and corresponding PostScript file of the latest printing of the ... MATLAB is an interactive, matrix-based system for scientific and engineering numeric .... multiple windows, you will want to keep MATLAB active in one window and

MATLAB - Ohjelmointi.pdf
Page 1. Whoops! There was a problem loading more pages. Retrying... MATLAB - Ohjelmointi.pdf. MATLAB - Ohjelmointi.pdf. Open. Extract. Open with. Sign In.

System Objects in MATLAB Code Generation - MATLAB & Simulink ...
System Objects in MATLAB Code Generation - MATLAB & Simulink.pdf. System Objects in MATLAB Code Generation - MATLAB & Simulink.pdf. Open. Extract.