Partition Video Frames to Multiple Image Files

In this example, you use the To Multimedia File block, the Enabled Subsystem block, and a trigger signal, to save portions of one AVI file to three separate AVI files.

You can open the example model with the link below or by typing

ex_vision_partition_video_frames_to_multiple_filesex_vision_partition_video_frames_to_multiple_files

at the MATLAB® command line.

  1. Run your model.

  2. The model saves the three output AVI files in your current folder.

  3. View the resulting files by typing the following commands at the MATLAB command prompt:

    mplay output1.avi
    mplay output2.avi
    mplay output3.avi 
    
  4. Press the Play button on the MPlay GUI.

For more information on the blocks used in this example, see the From Multimedia File, Insert Text, Enabled Subsystem, and To Multimedia File block reference pages.

Setting Block Parameters for this Example

The block parameters in this example were modified from default values as follows:

BlockParameter
From Multimedia FileThe From Multimedia File block imports an AVI file into the model.
  • Cleared Inherit sample time from file checkbox.

Insert TextThe example uses the Insert Text block to annotate the video stream with frame numbers. The block writes the frame number in green, in the upper-left corner of the output video stream.
  • Text: 'Frame %d'

  • Color: [0 1 0]

  • Location: [10 10]

To Multimedia File

The To Multimedia File blocks send the video stream to three separate AVI files. These block parameters were modified as follows:

  • Output file name: output1.avi, output2.avi, and output3.avi, respectively

  • Write: Video only

Counter

The Counter block counts the number of video frames. The example uses this information to specify which frames are sent to which file. The block parameters are modified as follows:

  • Number of bits: 8

  • Sample time: 1/30

Bias

The bias block adds a bias to the input. The block parameters are modified as follows:

  • Bias: 1

Compare to Constant

The Compare to Constant block sends frames 1 to 9 to the first AVI file. The block parameters are modified as follows:

  • Operator: <

  • Constant value: 10

Compare to Constant1
Compare to Constant2

The Compare to Constant1 and Compare to Constant2 blocks send frames 10 to 19 to the second AVI file. The block parameters are modified as follows:

  • Operator: >=

  • Constant value: 10

The Compare to Constant2 block parameters are modified as follows:

  • Operator: <

  • Constant value: 20

Compare to Constant3

The Compare to Constant3 block send frames 20 to 30 to the third AVI file. The block parameters are modified as follows:

  • Operator: >=

  • Constant value: 20

Compare to Constant4

The Compare to Constant4 block stopa the simulation when the video reaches frame 30. The block parameters are modified as follows:

  • Operator: ==

  • Constant value: 30

  • Output data type mode: boolean

Using the Enabled Subsystem Block

Each To Multimedia File block gets inserted into one Enabled Subsystem block, and connected to it's input. You can do this, by double-clicking the Enabled Subsystem blocks, then click-and-drag a To Multimedia File block into it.

Each enabled subsystem should look similar to the subsystem shown in the following figure.

Configuration Parameters

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

  • Solver pane, Type = Fixed-step

  • Solver pane, Solver = Discrete (no continuous states)

Was this topic helpful?