From Multimedia File
Read video frames and audio samples from multimedia file
- Library:
Computer Vision Toolbox / Sources
Description
TheFrom Multimedia Fileblock reads video frames, audio samples, or both from a multimedia file. The block imports data from a file, of a supported file format, into a Simulink®model. For more information about supported file formats, seeSupported Platforms and File Formats.
This block enables you to read WMA or WMV streams from your system or over a network connection. Similarly, theTo Multimedia Fileblock enables you to write WMA or WMV streams to your system or over a network connection. If your system does not have the codec necessary to support a file format, you must re-encode files of that format into a file format supported by the Computer Vision Toolbox™.
If you have aSimulink Coder™license, you can generate code from a model containing this block. To run a generated executable file, you may need to add precompiled shared library files to your system path. For more information, seeSimulink Shared Library DependenciesandAccelerating Simulink Models.
Note
This block supports code generation for a host computer that has file I/O available. You cannot use this block withSimulink Desktop Real-Time™software because that product does not support file I/O.
Ports
Output
Image
— Color image or video frame
array
Color image or video frame, returned as anM-by-N-by-Parray.MandNare the number of rows and columns in each image.Pis the number of color channels in each image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
RGB
andImage signalparameter toOne multidimensional signal
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
|Simulink.ImageType
I
——灰度我mage or video frame
matrix
Grayscale image or video frame, returned as anM-by-Nmatrix.MandNare the number of rows and columns in the grayscale image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
Intensity
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
R
— Red color component of image or video frame
matrix
Red color component of the image or video frame, returned as anM-by-Nmatrix.MandNare the number of rows and columns in the image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
RGB
andImage signalparameter toSeparate color signals
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
G
— Green color component of image or video frame
matrix
Green color component of the image or video frame, returned as anM-by-Nmatrix.MandNare the number of rows and columns in the image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
RGB
andImage signalparameter toSeparate color signals
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
B
— Blue color component of image or video frame
matrix
Blue color component of the image or video frame, returned as anM-by-Nmatrix.MandNare the number of rows and columns in the image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
RGB
andImage signalparameter toSeparate color signals
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
Y
— Luma component of image or video frame
matrix
Luma component of the image or video frame, returned as anM-by-Nmatrix.MandNare the number of rows and columns in the image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
YCbCr 4:2:2
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
Cb
— Blue-difference chrominance component of image or video frame
matrix
Blue-difference chrominance component of the image or video frame, returned as anM-by-N/2 matrix.MandNare the number of rows and columns in the input image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
YCbCr 4:2:2
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
Cr
— Red-difference chrominance component of image or video frame
matrix
Red-difference chrominance component of the image or video frame, returned as anM-by-N/2 matrix.MandNare the number of rows and columns in each input image.
Dependencies
To enable this port:
Set theFile nameparameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
YCbCr 4:2:2
.
Data Types:single
|double
|int8
|int16
|int32
|uint8
|uint16
|uint32
Audio
— Audio signal
vector | matrix
Audio signal, returned as anM-element vector or anM-by-Nmatrix.Mis the number of samples in each channel andNis the number of channels.
Dependencies
To enable this port, set theFile nameparameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toAudio only
orVideo and audio
.
Data Types:single
|double
|int16
|uint8
EOF
— End-of-file indicator
scalar
End-of-file indicator, returned as a logical scalar for each video frame or audio sample. The end-of-file indicator is1
when the block outputs the final video frame or audio sample from the file, and is0
otherwise.
Dependencies
To enable this port, select theOutput end-of-file indicatorparameter.
Data Types:Boolean
Parameters
Main
File name
— Name of multimedia file
vipmen.avi
(default) | character vector
Specify the name of the multimedia file for the block to read. If the file is not located on your MATLAB®path, select浏览and navigate to the file, or specify the full file path.
On Microsoft®Windows®platforms, this parameter supports URLs that point to Microsoft Media Server (MMS) streams.
Inherit sample time from file
— Inherit sample time from file
on
(default) |off
Specify whether the block inherits the sample time from the multimedia file or uses a specified sample time. When you select this parameter, the block inherits the sample time from the input multimedia file.
Tip
Select this parameter when you do not know the intended sample rate of the multimedia file.
Desired sample time
— Block sample time
1/30
(default) | real positive scalar
指定一个样品时间。
Dependencies
To enable this parameter, clear theInherit sample time from fileparameter.
Number of times to play file
— Number of times to play multimedia file
inf
(default) | real positive integer
Specify the number of times to play the input multimedia file. The default value ofinf
specifies that the block repeats playing the multimedia file until the simulation stop time.
Output end-of-file indicator
— End-of-file indicator
off
(default) |on
Select this parameter to enable theEOFport, which indicates whether the output frame or sample is the final video frame or audio sample in the multimedia file.
Multimedia outputs
— Type of media
Video only
(default) |Audio only
|Video and audio
Specify the type of media to read from a file containing both video and audio data.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains both audio and video data.
Output color format
— Color format of video
RGB
(default) |Intensity
|YCbCr 4:2:2
Specify the output color format of the input video data. The block supports theRGB
,Intensity
, andYCbCr 4:2:2
color formats.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toVideo only
orVideo and audio
.
Image signal
— Output port configuration for RGB video
One multidimensional signal
(default) |Separate color signals
|Simulink image signal
Specify how the block outputs an RGB color video. If you selectOne multidimensional signal
, the block outputs the video data using only theImage端口。如果您选择Separate color signals
, the block outputs the video data using three separate color channels, divided across theR,G, andBports. If you selectSimulink image signal
, the block outputs a video inSimulink.ImageType
datatype.
Dependencies
To enable this parameter:
Set theFile nameparameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set theMultimedia outputsparameter to
Video only
orVideo and audio
.Set theOutput color formatparameter to
RGB
.
Read range
— Range of audio samples
[1 Inf]
(default) | two-element row vector
Specify the range of audio samples to read from the input file as a two-element row vector of the form[StartSample EndSample]
.StartSample
is the first sample the block reads from the audio file, andEndSample
is the final sample the block reads from the audio file.StartSample
must be greater than or equal to1
.EndSample
must be greater thanStartSample
.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toAudio only
.
Samples per audio channel
— Samples per audio channel
1024
(default) | real positive integer
Specify the number of samples per audio channel.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toAudio only
.
Data Types
Video output data type
— Video output data type
single
(default) |double
|int8
|uint8
|int16
|uint16
|int32
|uint32
|Inherit from file
Specify the data type for the output video frames.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toVideo only
orVideo and audio
.
Audio output data type
— Audio output data type
int16
(default) |double
|single
|uint8
Specify the data type for the output audio samples.
Dependencies
To enable this parameter, set theFile nameparameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputsparameter toAudio only
orVideo and audio
.
Model Examples
Block Characteristics
More About
Supported Platforms and File Formats
Which supported file formats are available to you depends on the codecs installed on your system.
Platform | Supported File Formats |
---|---|
All Platforms | AVI (.avi )Motion JPEG 2000 ( .mj2 ) |
Microsoft Windows |
Image: JPEG( .jpg )Bitmap ( .bmp ) |
Video: MPEG ( .mpeg )MPEG-2 ( .mp2 )MPEG-1 ( .mpg )MPEG-4, including H.264 encoded video ( .mp4 ,.m4v )Windows Media Video ( .wmv ,.asf ,.asx )Any format supported by Microsoft DirectShow® 9.0 or higher. |
|
Audio: WAVE ( .wav )Windows Media Audio File ( .wma )Audio Interchange File Format ( .aif ,.aiff )Compressed Audio Interchange File Format ( .aifc )MP3 ( .mp3 )Sun Audio ( .au )Apple( .snd ) |
|
macOS | Video: MPEG-4, including H.264 encoded video ( .mp4 ,.m4v )Apple QuickTime Movie ( .mov )Any format supported byQuickTime. |
Audio: Uncompressed AVI ( .avi ) |
|
Linux® | 已安装的插件fo任何格金宝app式的支持r GStreamer 0.1 or higher, including Ogg Theora (.ogg ). |
Sample Time Calculations Used for Video and Audio Files
The sample rate that the block uses depends on the audio and video sample rate. While the block operates at a single rate in Simulink, the underlying audio and video streams can produce different rates. In some cases, the block makes a small adjustment to the video rate when the block outputs both audio and video.
Sample time =
.AudioSampleRateis the sample rate for audio data, andFPSis the video frame rate.
When the audio sample time,
, is not an integer,, the equation cannot reduce to
.
To prevent synchronization problems, when the audio stream leads the video stream by more than
, the block drops the corresponding video frame.
In summary, the block outputs one video frame at each Simulink time step. To calculate the number of audio samples to output at each time step, the block divides the audio sample rate by the video frame rate. If the audio sample rate does not divide evenly by the number of video frames per second (FPS), the block rounds the number of audio samples up to the nearest whole number. If necessary, the block periodically drops a video frame to maintain synchronization for large files.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
使用notes and limitations:
Host computer only. Excludes Simulink Desktop Real-Time code generation.
The executable generated from this block relies on prebuilt dynamic library files (
.dll
files) included with MATLAB. Use thepackNGo
(Simulink Coder)function to package the code generated from this block and all the relevant files in a compressed ZIP file. Using this ZIP file, you can relocate, unpack, and rebuild your project in another development environment where MATLAB is not installed.
Version History
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- 比利时(English)
- Denmark(English)
- Deutschland(德语)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(德语)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)