Main Content

smwritevideo

Configure and create multibody animation videos

Description

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.

example

Examples

collapse all

Create a video named FlappingWingVideo from the simulation results of the Using the Point-On-Curve Block: Flapping Wing Mechanism example.

  • Open the flapping wing example.

openExample("sm/PointOnCurveExample");
  • Simulate the model.

sim("PointOnCurve");

Create a Video with Default Settings

Create a video of the simulation results.

smwritevideo("PointOnCurve","FlappingWingVideo");

The function saves the video as FlappingWingVideo in the current MATLAB® folder. The video file uses the default setting. format is that specified in the Video Creator app. Open the video using your media player of choice.

flapping_wing_vis.gif

Create a Video with Custom Settings

Alternatively, you can create a video with custom settings. For example, you can create a video for the model with these settings.

smwritevideo("PointOnCurve","FlappingWingVideoCustom",...
"PlaybackSpeedRatio",2.0,"FrameRate",60,"VideoFormat","uncompressed avi");

The function saves the video as FlappingWingVideoCustom.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.

Create Video from Tile of Split Screen

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

  • In Mechanics Explorer, select View > Layout > Four Standard Views. The top left tile (number 1) is by default the active tile.

  • Record a video from the bottom left tile (number 2). At the MATLAB command prompt enter:

smwritevideo("PointOnCurve","FlappingWingVideo2","tile",2);

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: ‘PointOnCurveExample’

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