From Multimedia File - Stream from multimedia file - Simulink (original) (raw)
Stream from multimedia file
Libraries:
Audio Toolbox / Sources
DSP System Toolbox / Sources
Description
The From Multimedia File block reads audio samples, video frames, or both from a multimedia file and generates a signal with one of the following data types and amplitude ranges.
Output Data Type | Output Amplitude Range |
---|---|
double | ±1 |
single | ±1 |
int16 | −32768 to 32767 (−215 to 215 − 1) |
uint8 | 0 to 255 |
The block imports data from the file into a Simulink® model.
Note
This block supports code generation for a host computer that has file I/O available. You cannot use this block with Simulink Desktop Real-Time™ software because that product does not support file I/O. The generated code for this block relies on prebuilt library files. For more details, see Code Generation.
Examples
Limitations
To support OPUS file format on a Linux® machine, you must have libsndfile 1.0.29
or a later version installed. On Windows® and Mac, this file is shipped with MATLAB® and is available under$MATLABROOT/bin/<platform>
.
Ports
The output ports of the From Multimedia File block change according to the content of the multimedia file. If the file contains only video frames, theImage port, intensity I port,R,G,B ports, orY,Cb,Cr ports appear based on the settings on the block dialog box. If the file contains only audio samples, the Audio port appears on the block. If the file contains both audio and video, you can select the data to emit. This section describes these ports in more detail.
Output
Color image or video frame, returned as an_M_-by-_N_-by-P array. M and N are the number of rows and columns in each image. P is the number of color channels in each image.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
RGB
andImage signal parameter toOne multidimensional signal
. - This port is named as Simulink Image if the Output color format parameter is set to
RGB
and theImage signal parameter is set toSimulink image signal
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Simulink.ImageType
Grayscale image or video frame, returned as an_M_-by-N matrix.M and N are the number of rows and columns in the grayscale image.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
Intensity
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Red color component of the image or video frame, returned as an_M_-by-N matrix.M and N are the number of rows and columns in the image.
Outputs from the R, G, orB ports must have the same dimensions.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
RGB
andImage signal parameter toSeparate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Green color component of the image or video frame, returned as an_M_-by-N matrix.M and N are the number of rows and columns in the image.
Outputs from the R, G, orB ports must have the same dimensions.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
RGB
andImage signal parameter toSeparate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Blue color component of the image or video frame, returned as an_M_-by-N matrix.M and N are the number of rows and columns in the image.
Outputs from the R, G, orB ports must have the same dimensions.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
RGB
andImage signal parameter toSeparate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Luma component of the image or video frame, returned as an_M_-by-N matrix.M and N are the number of rows and columns in the image.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
YCbCr 4:2:2
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Blue-difference chrominance component of the image or video frame, returned as an _M_-by-N/2 matrix.M and N are the number of rows and columns in the input image.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
YCbCr 4:2:2
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Red-difference chrominance component of the image or video frame, returned as an _M_-by-N/2 matrix.M and N are the number of rows and columns in each input image.
Dependencies
To enable this port:
- Set the File name parameter to the name of a multimedia file that contains video or image data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
YCbCr 4:2:2
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Audio signal, returned as an M_-element vector or an_M_-by-N matrix.M is the number of samples in each channel and_N is the number of channels.
Dependencies
To enable this port, set the File name parameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toAudio only
or Video and audio
.
Data Types: single
| double
| int16
| uint8
End-of-file indicator, returned as a logical scalar for each video frame or audio sample. The end-of-file indicator is 1
when the block outputs the final video frame or audio sample from the file, and is 0
otherwise.
Dependencies
To enable this port, select the Output end-of-file indicator parameter.
Data Types: Boolean
Parameters
Main Tab
Specify the name of the multimedia file for the block to read. The block determines the type of file (audio and video, audio only, or video only) and provides the associated parameters.
If the location of the file does not appear on the MATLAB path, use the Browse button to specify the full path. If the location of the file appears on the MATLAB path, enter only the file name.
On Windows platforms, this parameter supports URLs that point to MMS (Microsoft Media Server) streams.
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. When you clear this parameter, the block uses the sample time that you specify in the Desired sample time parameter.
Tip
Select this parameter when you do not know the intended sample rate of the multimedia file.
Specify the block sample time.
Dependencies
To enable this parameter, clear the Inherit sample time from file parameter.
Specify the number of times to play the input multimedia file. The default value of inf
specifies that the block repeats playing the multimedia file until the simulation stop time.
Specify the sample range from which to read as a two-element row vector in the form of [StartSample EndSample_], where StartSample is the sample at which file reading starts, and_EndSample is the sample at which file reading stops.
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toAudio only
.
Use this parameter to determine whether the output is the last video frame or audio sample in the multimedia file. When you select this parameter, a Boolean
output port labeledEOF appears on the block. The output from theEOF port defaults to 1 when the last video frame or audio sample is output from the block. Otherwise, the output from the EOF port defaults to 0.
Specify the type of media to read from a file containing both video and audio data.
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains both audio and video data.
Specify number of samples per audio channel. This parameter becomes available for files containing audio.
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toAudio only
.
Specify the output color format of the input video data. The block supports the RGB
,Intensity
, and YCbCr 4:2:2
color formats.
If you select RGB
, use the Image signal parameter to specify how to output a color signal.
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toVideo only
or Video and audio
.
Specify how the block outputs an RGB color video. If you select:
One multidimensional signal
–– The block outputs an_M_-by-_N_-by-P color video signal through the Image port, where P is the number of color planes.Separate color signals
–– The block outputs the video data using three separate color channels, divided across the R,G, and B ports. Each port outputs one_M_-by-N plane of an RGB video stream.Simulink image signal
–– The block outputs a video inSimulink.ImageType
datatype.
Dependencies
To enable this parameter:
- Set the File name parameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set the Multimedia outputs parameter to
Video only
orVideo and audio
. - Set the Output color format parameter to
RGB
.
Data Types Tab
Specify the data type for the audio samples output at theAudio port.
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains audio data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toAudio only
or Video and audio
.
Specify the data type of the video frames output at theR, G,B, or Image ports..
Dependencies
To enable this parameter, set the File name parameter to the name of a multimedia file that contains video data. If the specified file contains both audio and video data, set theMultimedia outputs parameter toVideo only
or Video and audio
.
Block Characteristics
Data Types | double | integera | single |
---|---|---|
Direct Feedthrough | no | |
Multidimensional Signals | no | |
Variable-Size Signals | no | |
Zero-Crossing Detection | no | |
a Supports 16- and 32-bit signed and 8-bit unsigned integers. |
More About
The supported file formats available to you depends on the codecs installed on your system.
Windows Platforms Supported File Formats
With the necessary Windows DirectShow codecs installed on your system, the From Multimedia File Block supports many video and audio file formats. This block performs best on platforms with Version 9.0 or later of DirectX® software.
The following table lists the most common file formats.
Multimedia Types | File Name Extensions |
---|---|
Image files | .jpg, .bmp,.png |
Video files | .qt, .mov,.avi, .asf,.asx, .wmv,.mpg, .mpeg,.mp2, .mp4,.m4v |
Audio files | .wav, .wma,.avi, .aif,.aifc, .aiff,.mp3, .au,.snd, .mp4,.m4a, .flac,.ogg, .opus |
The default for image files is .png
, for video files is.avi
, and for audio files is.mp3
.
Windows 7 and later versions of Windows ship with a limited set of 64-bit video and audio codecs. If the From Multimedia File block cannot work on a compressed multimedia file, save the multimedia file to a file format supported by the block.
If you use Windows, use Windows Media® Player Version 11 or later with this block for best results.
Non- Windows Platform Supported File Formats
The following table lists the most common file formats.
Multimedia Types | File Name Extensions |
---|---|
Video files | .avi, .mj2,.mov, .mp4,.m4v |
Audio files | .avi, .mp3,.mp4, .m4a,.wav, .flac,.ogg, .aif,.aifc, .aiff,.au, .opus,.snd |
The default for video files is .avi
and for audio files is.mp3
.
The sample rate that the block uses depends on the audio and video sample rate. While the From Multimedia File block operates at a single rate in Simulink, the underlying audio and video streams can produce different rates. In some cases, when the block outputs both audio and video, it makes a small adjustment to the video rate.
Sample time = ceil(AudioSampleRateFPS)AudioSampleRate.
When the audio sample time AudioSampleRateFPS is noninteger, the equation cannot reduce to 1FPS.
In this case, to prevent synchronization problems, the block drops the corresponding video frame when the audio stream leads the video stream by more than 1FPS.
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 (fps). If the audio sample rate does not divide evenly by the number of video frames per second, 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.
To run your generated standalone executable application in Shell, you need to set your environment to the following:
Platform | Command |
---|---|
Mac | setenv DYLD_LIBRARY_PATH "${DYLD_LIBRARY_PATH}:$MATLABROOT/bin/maca64" (csh/tcsh on Apple silicon)export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$MATLABROOT/bin/maca64 (Bash on Apple silicon)setenv DYLD_LIBRARY_PATH "${DYLD_LIBRARY_PATH}:$MATLABROOT/bin/maci64" (csh/tcsh on Mac Intel®)export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$MATLABROOT/bin/maci64 (Bash on Mac Intel)For more information, see "DYLD_LIBRARY_PATH" in MAC. |
Linux | setenv LD_LIBRARY_PATH LDLIBRARYPATH:{LD_LIBRARY_PATH}:LDLIBRARYPATH:MATLABROOT/bin/glnxa64 (csh/tcsh) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MATLABROOT/bin/glnxa64 (Bash) |
Windows | set PATH=%PATH%;%MATLABROOT%\bin\win64 |
Extended Capabilities
Usage 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
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. For more details, see How To Run a Generated Executable Outside MATLAB.
Version History
Introduced before R2006a
The From Multimedia File block supports audio files in the OPUS file format (.opus
).