NetLogo Vid Extension

Concepts

Video Source

The vid extension has a built-in concept of a video source. At the moment, the only video sources available are movies in the directory the model lives in and cameras attached to the computer. The vid extension opens a new video source with the vid:<source>-open and vid:<source>-select. These primitives change the source to the selected source. If a source is already open, it closes it before opening a new one.

Source Lifecycle

Movie sources are “stopped” after being created by vid:movie-select or vid:movie-open. Camera sources start off as “playing” after being created by vid:camera-select or vid:camera-open. If a source is in status “stopped” it can be started with vid:start. Conversely, if the source is “playing” it can be stopped with vid:stop. When a source is “stopped”, each call to vid:capture-image will return the same image.

Video Recorder

The vid extension also has the concept of a recording, a series of frames which can be sewn into an “mp4” movie. The recorder status can be queried using vid:recorder-status. The recorder status is “inactive” until started with vid:start-recorder, which sets it to “recording”. While the recorder is “recording” the vid:record-view, vid:record-interface, and vid:record-source can be used to save frames to the recording. You can choose to save the recording while recording using vid:save-recording which saves the movie to the specified file and reset the recording status to “inactive”. If you would prefer to throw away the recorded frames without saving, use vid:reset-recorder.

Primitives

vid:camera-names vid:camera-open vid:camera-select vid:movie-select vid:movie-open vid:movie-open-remote vid:close vid:start vid:stop vid:status vid:capture-image vid:set-time vid:show-player vid:hide-player vid:record-view vid:record-interface vid:record-source vid:recorder-status vid:start-recorder vid:save-recording

vid:camera-names

vid:camera-names

Provides a list of all available cameras.

Example:

vid:camera-open

vid:camera-open

Opens the named camera as a video source. If no name is provided, opens the first camera that would be listed by camera-names.

Example:

Errors:

vid:camera-select

vid:camera-select

Prompts the user to select a camera as video source. This command does not error if the user cancels. Use vid:status to see if a user selected a camera.

Example:

Errors:

vid:movie-select

vid:movie-select

Prompts the user to select a movie to use as a video source. The formats supported are those supported by JavaFX2. This command does not error if the user cancels. Use vid:status to see if the user selected a movie.

Example:

Errors:

vid:movie-open

vid:movie-open filename

Opens a video from the file system. If the provided path is not absolute the extension searches for the given path relative to the current model directory. If the provided path is absolute the extension opens the file.

Example:

Errors:

vid:movie-open-remote

vid:movie-open-remote url

Opens a remote video from a website or ftp server.

Example:

Errors:

vid:close

vid:close

Closes the currently selected video source. Has no effect if there is no active video source.

Example:

vid:start

vid:start

Starts the selected video source. A video source must have been selected before calling vid:start.

Example:

Errors:

vid:stop

vid:stop

Stops the currently running video source.

Example:

vid:status

vid:status

Reports the current status of an active video. Note that after calling vid:movie-open or vid:movie-select the status will be set to “stopped”, while after calling vid:camera-open or vid:camera-select the status will be “playing”.

Example:

vid:capture-image

vid:capture-image width height

Captures an image from the currently selected active source.

If width and height are not specified, the image is captured at the current source resolution.

Example:

If you want to capture images at a different resolution, simply replace vid:capture-image with, e.g., (vid:capture-image 640 480).

Errors:

vid:set-time

vid:set-time seconds

Sets the time of the current video source to *seconds*. This has no effect when the current video source is a camera.

Example:

Errors:

vid:show-player

vid:show-player width height

Shows a player in a separate window. If there is no video source, the window will be an empty black frame. If there is an active video source, it will be displayed in the window with the specified width and height. If there is a playing video source, it will be displayed in the window at its specified width and height. If width and height are omitted, the video will be displayed in its native resolution.

Example with native resolution:

Example with custom resolution:

Errors:

vid:hide-player

vid:hide-player

Hides the player if open. Does nothing if there is no player window.

Example:

vid:record-view

vid:record-view

Records the current image shown in the NetLogo view to the active recording.

Example:

Errors:

vid:record-interface

vid:record-interface

Records the NetLogo interface view to the active recording.

Example:

Errors:

vid:record-source

vid:record-source

Records a frame to the active recording from the currently active source.

Example:

Errors:

vid:recorder-status

vid:recorder-status

Reports the current status of the recorder. Initially and after the recorder is saved (via vid:save-recording) or reset (via vid:reset-recorder) the recorder status is “inactive”. After calling vid:start-recorder the status will be “recording”.

Example:

vid:start-recorder

vid:start-recorder

Starts the recorder. If the recorder is already running this will cause an error to be raised. If desired, a recording width and height can be supplied. If width and height are not supplied, they will be determined from the first frame recorded.

Example:

Errors:

vid:save-recording

vid:save-recording filename

Saves the recording to the specified path. If the recorder is not running this will cause an error to be raised. Note that at present the recording will always be saved in the “mp4” format. If the supplied filename does not end in “.mp4”, the “.mp4” suffix will be added. Note that vid:save-recording will overwrite existing files of the same name. vid:save-recording will error if the recorder has not been started or if the file cannot be written since the containing directory does not exist.

Example:

Errors: