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
on the MATLAB® command line.
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.
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.
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.