Video
Last updated
Was this helpful?
Last updated
Was this helpful?
By using the video
, videos can be displayed an OSL program. To initialize a video, simply render it using the following syntax:
OSL handles all the fetching and loading of videos internally the first time a URL is used. However, videos take a while to load; you may notice that when running the example script above, the screen will be black for several frames while the video initializes. To work around this, we can initialize the video before it's displayed by using the "load" argument.
To manipulate a video's state, we first need to identify the video's ID. All videos created in OSL have a video ID. Typically, this ID is just the same as the URL you used to initialize the video. However, when pre-loading a video using the "load" argument, a custom ID can be chosen for the video.
You may notice that when loading a video, it doesn't begin playing right away. That's because when initialized, a video begins paused; to unpause it, the "play" command must be called. Inversely, the "pause" command can return the video to a non-playing state.
To seek (or jump to a specific part of) a video, the aptly named "seek" argument is used. By specifying a time in seconds, we can start the video at that point. Note that if the video was paused before calling "seek," this command resumes playback—the video can be paused after using "seek" to mitigate this.
By using the "volume" and "speed" commands, we can tinker with those values as well. By default, volume is set to 100 and playback speed is set to 1.
To clear a video from memory, the "clear" argument can be used.
.videoInfo("loaded")
Boolean
Returns whether a video has been fully initialized or not.
.videoInfo("playing")
Boolean
Returns if a video is actively playing content; in other words, checks if the video is paused or not.
.videoInfo("width")
Number
Return the video's width in pixels.
.videoInfo("height")
Number
Return the video's height in pixels.
.videoInfo("current_time")
Number
Return the current time of the video in seconds.
.videoInfo("duration")
Number
Return the runtime of the video in seconds.
.videoInfo("volume")
Number
Returns the volume of the video; defaults to 100, but can be set using the "volume" argument above.
By using the .videoInfo()
after the video ID, information about the respective video can be accessed. The method takes one argument, which specifies which data to return.