Documentation

From Multimedia File

Stream from multimedia file

Library

Sources

dspsrcs4

Description

TheFrom Multimedia Fileblock reads audio samples, video frames, or both from a multimedia file. The block imports data from the file into a Simulink®model.

Note

This block supports code generation for the 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.

The generated code for this block relies on prebuilt library files. You can run this code outside the MATLAB®environment, or redeploy it, but be sure to account for these extra library files when doing so. The packNGo function creates a single zip file containing all of the pieces required to run or rebuild this code. SeepackNGofor more information.

To run an executable file that was generated from a model containing this block, you may need to add precompiled shared library files to your system path. SeeUnderstanding C Code Generation in DSP System Toolboxfor details.

Supported Platforms and File Types

The supported file formats available to you depends on the codecs installed on your system.

WindowsPlatforms Supported File Formats

With the necessary Windows®DirectShow codecs installed on your system, theFrom Multimedia FileBlock 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 文件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

The default for image files is.png, for video files is.avi, and for audio files is.mp3.

Windows 7and later versions of Windows ship with a limited set of 64-bit video and audio codecs. If theFrom Multimedia Fileblock cannot work on a compressed multimedia file, save the multimedia file to a file format supported by the block.

如果你use Windows, useWindows Media®球员Version 11 or later with this block for best results.

Non-WindowsPlatform Supported File Formats

The following table lists the most common file formats.

Multimedia Types 文件Name Extensions
Video files .avi,.mj2,.mov,.mp4,.m4v
Audio files .avi, .mp3, .mp4, .m4a, .wav, .flac, .ogg, .aif, .aifc, .aiff, .au, .snd

The default for video files is.avi, and for audio files is.mp3.

Ports

The output ports of theFrom Multimedia Fileblock change according to the content of the multimedia file. If the file contains only video frames, theImage, intensityI, orR,G,Bports appear on the block. If the file contains only audio samples, theAudioport appears on the block. If the file contains both audio and video, you can select the data to emit. The following table describes available ports.

Port Description
Image

M-by-N-by-Pcolor video signal wherePis the number of color planes.

I

M-by-Nmatrix of intensity values.

R,G,B

Matrix that represents one plane of the RGB video stream. Outputs from the R, G, or B ports must have same dimensions.

Audio

Vector of audio data.

Y, Cb, Cr

Matrix that represents one frame of the YCbCr video stream. The Y, Cb, Cr ports produce the following outputs:

Y:M x N
Cb:M x N 2
Cr:M x N 2

Sample Rates

The sample rate that the block uses depends on the audio and video sample rate. While the FMMF 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, makes a small adjustment to the video rate.

Sample Time Calculations Used for Video and Audio Files

Sample time = c e i l ( A u d i o S a m p l e R a t e F P S ) A u d i o S a m p l e R a t e .
When audio sample time, A u d i o S a m p l e R a t e F P S is noninteger, the equation cannot reduce to 1 F P S .

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 1 F P S .
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.

Dialog Box

Main Tab

File name

Specify the name of the multimedia file from which 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 your MATLAB path, use theBrowsebutton to specify the full path. Otherwise, if the location of this file appears on your MATLAB path, enter only the file name. On Windows platforms, this parameter supports URLs that point to MMS (Microsoft Media Server) streams.

Inherit sample time from file

Select theInherit sample time from filecheck box if you want the block sample time to be the same as the multimedia file. If you clear this check box, enter the block sample time in theDesired sample timeparameter field. The file that theFrom Multimedia Fileblock references, determines the block default sample time. You can also set the sample time for this block manually. If you do not know the intended sample rate of the video, let the block inherit the sample rate from the multimedia file.

Desired sample time

Specify the block sample time. This parameter becomes available if you clear theInherit sample time from filecheck box.

p的次数lay file

Enter a positive integer orinfto represent the number of times to play the file.

Output end-of-file indicator

Use this check box to determine whether the output is the last video frame or audio sample in the multimedia file. When you select this check box, a Boolean output port labeled EOF appears on the block. The output from the EOF 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.

Multimedia outputs

SpecifyVideo and audio,Video only, orAudio onlyoutput file type. This parameter becomes available only when a video signal has both audio and video.

样品/音频通道

Specify number of samples per audio channel. This parameter becomes available for files containing audio.

Output color format

Specify whether you want the block to outputRGB,Intensity, orYCbCr 4:2:2video frames. This parameter becomes available only for a signal that contains video. If you selectRGB, use theImage signalparameter to specify how to output a color signal.

Image signal

指定如何输出彩色视频信号。如果你selectOne multidimensional signal, the block outputs anM-by-N-by-Pcolor video signal, wherePis the number of color planes, at one port. If you selectSeparate color signals, additional ports appear on the block. Each port outputs oneM-by-Nplane of an RGB video stream. This parameter becomes available only if you set theOutput color formatparameter toRGBand the signal contains video.

Data Types Tab

Audio output data type

Set the data type of the audio samples output at the Audio port. This parameter becomes available only if the multimedia file contains audio. You can choosedouble,single,int16, oruint8types.

Video output data type

Set the data type of the video frames output at theR,G,B, orImageports. This parameter becomes available only if the multimedia file contains video. You can choosedouble,single,int8,uint8,int16,uint16,int32,uint32, orInherit from filetypes.

Troubleshooting

Running an Executable OutsideMATLAB

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/maci64" (csh/tcsh)

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$MATLABROOT/bin/maci64 (Bash)

Linux

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:$MATLABROOT/bin/glnxa64 (csh/tcsh)

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MATLABROOT/bin/glnxa64 (Bash)

Windows

set PATH=%PATH%;%MATLABROOT%\bin\win64

Supported Data Types

For source blocks to display video data properly, double- and single-precision floating-point pixel values must be between0and1. For other data types, the pixel values must be between the minimum and maximum values supported by their data type.

Port Supported Data Types Supports Complex Values?

Image

  • Double-precision floating point

  • Single-precision floating point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

No

R, G, B

Same as the Image port

No

Audio

  • Double-precision floating point

  • Single-precision floating point

  • 16-bit signed integers

  • 8-bit unsigned integers

No

Y, Cb,Cr

Same as the Image port

No

Extended Capabilities

Introduced before R2006a

Was this topic helpful?