Documentation Center

  • Trial Software
  • Product Updates

Combine Video and Audio Streams

In this example, you use the From Multimedia File blocks to import video and audio streams into a Simulink® model. You then write the audio and video to a single file using the To Multimedia File block.

You can open the example model by typing

ex_combine_video_and_audio_streamsex_combine_video_and_audio_streams

on the MATLAB® command line.

  1. Run your model. The model creates a multimedia file called output.avi in your current folder.

  2. Play the multimedia file using a media player. The original video file now has an audio component to it.

Setting Up the Video Input Block

The From Multimedia File block imports a video file into the model. During import, the Inherit sample time from file check box is deselected, which enables the Desired sample time parameter. The other default parameters are accepted.

The From Multimedia File block used for the input video file inherits its sample time from the vipmen.avi file. For video signals, the sample time equals the frame period. The frame period is defined as 1/(frame rate). Because the input video frame rate is 30 frames per second (fps), the block sets the frame period to 1/30 or 0.0333 seconds per frame.

Setting Up the Audio Input Block

The From Multimedia File1 block imports an audio file into the model.

The Samples per audio frame parameter is set to 735. This output audio frame size is calculated by dividing the frequency of the audio signal (22050 samples per second) by the frame rate (approximately 30 frames per second).

You must adjust the audio signal frame period to match the frame period of the video signal. The video frame period is 0.0333 seconds per frame. Because the frame period is also defined as the frame size divided by frequency, you can calculate the frame period of the audio signal by dividing the frame size of the audio signal (735 samples per frame) by the frequency (22050 samples per second) to get 0.0333 seconds per frame.

frame period = (frame size)/(frequency)
frame period = (735 samples per frame)/(22050 samples per second)
frame period = 0.0333 seconds per frame

Alternatively, you can verify that the frame period of the audio and video signals is the same using a Simulink Probe block.

Setting Up the Output Block

The To Multimedia File block is used to output the audio and video signals to a single multimedia file. The Video and audio option is selected for the Write parameter and One multidimensional signal for the Image signal parameter. The other default parameters are accepted.

Configuration Parameters

You can locate the Configuration Parameters by selecting Model Configuration Parameters from the Simulation menu. The parameters, on the Solver pane, are set as follows:

  • Stop time = 10

  • Type = Fixed-step

  • Solver = Discrete (no continuous states)

Was this topic helpful?