Main Content

smwritevideo

Configure and create multibody animation videos

Description

example

smwritevideo(modelIdentifier,videoName) creates a video from the visualization of a multibody model. modelIdentifier is the source model name or handle. videoName is the generated video file name and path. You can open the video file with any compatible media player.

The video properties are those specified in the Video Creator interface the moment you run the function. If the Video Creator parameters are in their default settings, the video properties are set to those defaults.

Before running smwritevideo, you must simulate the model. In addition, the model visualization results must open in a Mechanics Explorer window. If you have previously disabled model visualization, reenable it before continuing. To do this, see Enable Mechanics Explorer.

By default, if the model visualization pane is split into tiles, the function captures only the active tile. A colored outline identifies the active tile. You can click a tile to make it the active tile—or use the tile name-value pair argument to specify the number of the tile to record.

example

smwritevideo(modelIdentifier,videoName,Name,Value) adds options for specifying the video properties. Use the Name,Value pair arguments to set the visualization tile to record, the video file format, the frame refresh rate, the frame width and height, and the playback speed ratio. Unused arguments are set to the latest settings specified in the Video Creator tool.

Examples

collapse all

Create a video named flapping_wing_video from the simulation results of the sm_cam_flapping_wing featured example. Use the video settings currently specified in the Video Creator tool.

  1. Open the flapping wing featured example.

    sm_cam_flapping_wing

  2. Simulate the model.

    sim('sm_cam_flapping_wing')
  3. Create a video of the simulation results.

    smwritevideo('sm_cam_flapping_wing','flapping_wing_video');
    The function saves the video as flapping_wing_video in the current MATLAB® folder. The video file format is that specified in the Video Creator tool. Open the video using your media player of choice.

Split the visualization pane for the sm_cam_flapping_wing model and record a video named flapping_wing_video from a specified tile.

  1. Open the flapping wing featured example.

    sm_cam_flapping_wing

  2. Simulate the model.

    sim('sm_cam_flapping_wing')
  3. In Mechanics Explorer, click the quad view button or select View > Layout > Four Standard Views. The top left tile (numbered 1) is by default the active tile.

  4. Record a video from the bottom right tile (numbered 4 in a counting scheme that runs first top to bottom and then left to right).

    smwritevideo('sm_cam_flapping_wing','flapping_wing_video','tile','4');
    The function saves the video as flapping_wing_video in the current MATLAB folder. The video file format is that specified in the Video Creator tool. Open the video using your media player of choice.

Create a video named wishbone_suspension_video from the simulation results of the sm_double_wishbone_suspension featured example. Change the video settings as shown in the table.

PropertyArgumentSetting
Playback Speed RatioPlaybackSpeedRatio2.0
Frame Rate (FPS)FrameRate60
Video FormatVideoFormatuncompressed avi

  1. Open the wishbone suspension featured example.

    sm_double_wishbone_suspension

  2. Simulate the model.

    sim(s'm_double_wishbone_suspension')
  3. Create a video of the simulation results.

    smwritevideo('sm_double_wishbone_suspension', 'wishbone_suspension_video',...
    'PlaybackSpeedRatio', 2.0, 'FrameRate', 60, 'VideoFormat', 'uncompressed avi');
    The function saves the video as wishbone_suspension_video.avi in the current MATLAB folder. Open the video using your media player of choice. The video plays at twice the original speed seen in Mechanics Explorer.

Input Arguments

collapse all

Name or handle of the source model, specified as a MATLAB string. You must simulate the specified model before using this function. The model visualization window must be open in order for the function to create a video.

Example: ‘sm_cam_flapping_wing’

Data Types: string

Name and full or relative path of the video file, specified as a string. In the absence of a file path, the function saves the video file in the current MATLAB folder. The file format is determined from the video settings specified using the Video Creator tool or the VideoFormat Name,Value pair argument.

Example: ‘flapping_wing_video’

Data Types: string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'PlaybackSpeedRatio', 2.0

Video playback speed relative to real time, specified as a positive scalar. Increase this factor for faster playback speeds. For example, a value of 2.0 doubles the video playback speed relative to the base playback speed used in Mechanics Explorer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of video frames per second of playback time, specified as a positive scalar. Increase this factor for smoother playback but larger video files. Small numbers may lead to choppy videos.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

File format to save the video in, specified as a string. Select from a list of compressed and uncompressed formats with varying quality levels and storage space requirements. Use the default format of uncompressed jpeg avi if file size is a concern. Use uncompressed avi if top video quality is a priority. The mpeg-4 format is not supported in Linux systems.

Data Types: string

Width (W) and height (H) of the video contents, specified in pixel units as the two-element row vector [W H]. The vector elements must be positive integers. Use the default setting of auto to obtain the video dimensions from the Mechanics Explorer visualization pane size.

Example: [800 800]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of the visualization tile to record. Use this parameter when the visualization pane is split and you want to record a tile other than the active tile (that enveloped in red highlight). Tiles are numbered first top to bottom and then left to right. In a quad view, the top left tile is numbered 1, the bottom left tile is 2, the top right tile is 3, and the bottom right tile is 4.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Version History

Introduced in R2016b