/  ChuGL Video Objects

Video

Webcam

Video and webcam access

Video

inherits : UGen_Multi : UGen : Object

ChuGL Video object. Currently supports decoding MPEG1 Video and MP2 Audio. Wraps the plmpeg library, which you can find here for more documentation: https://github.com/phoboslab/pl_mpeg/ (see link for an example on how to encode videos into a supported format with ffmpeg). This is a hybrid graphics/audio object. Video is a stereo UGen which may be connected dac for audio output. The video texture may be accessed with the `texture()` member function, which will be updated synchronously with audio. For sample-accurate audio manipulation, we recommend controlling the audio data separately with SndBuf. You can convert videos to the MPEG format with the following command-line ffmpeg command: `ffmpeg -i input.mp4 -c:v mpeg1video -q:v 0 -c:a mp2 -format mpeg output.mpg`.

examples

constructors

Video()

Default video constructor. Currently videos are not mutable -- i.e. you cannot change the video file after creation. This default constructor will create an empty video object and default to a static magenta video texture.Use the alternate constructor Video(string path) instead.

Video(string path)

Alternate video constructor. Opens a video file at the given path. Currently only supports MPEG1 video and MP2 audio. If the video file cannot be opened, the video object will default to a static magenta video texture.

member functions

Texture texture()

Get the RGBA texture of the video.

float framerate()

Get the framerate of the video.

float fps()

Get the framerate of the video.

int samplerate()

Get the samplerate of the video's audio stream.

dur duration()

Get total length of the file as a duration.

int width()

Get the width of the video in texels.

int height()

Get the height of the video in texels.

dur timestamp()

Get the current video playhead duration in seconds (time since video start)

void rate(float rate)

Set the playback rate of the video. 1.0 is normal speed. Due to limitations in the MPEG encoding format, rate cannot be set to less than 0.0. Reverse playback is NOT supported. Negative rates will be clamped to 0.

void rate()

Get the playback rate of the video. 1.0 is normal speed. Negative rates are not supported and will be clamped to 0.

int loop()

Get whether the video is looping. Default false.

void loop(int loop)

Set whether the video should loop. Default false.

void seek(dur time)

Seek to a specific time in the video. Negative values and values greater than the video length will wrap around. Note that seek is *not* sample-accurate; due to the nature of MPEG encoding (and the demands of real-time performance), the seek will be to the nearest keyframe, which in practice is within a few frames of the target time. For sample-accurate seeking and audio manipulation, we recommend loading the audio data separately into a SndBuf.


Webcam

inherits : SG_Component : Object

ChuGL Webcam class. Opens a webcam at any device id 0-7, and updates a texture with the webcam feed. The webcam texture may be accessed with the `.texture()` member function.

examples

constructors

Webcam()

Create a webcam object with default device id 0. On laptops this is usually the built-in webcam.

Webcam(int device_id)

Create a webcam object with a specific device id. On laptops, device id 0 is usually the built-in webcam.

Webcam(int device_id, int width, int height, int fps)

Create a webcam object with a specific device id and format. Will fallback to the nearest supported width/height/fps. Choose device_id 0 for laptop builtin webcam.

member functions

Texture texture()

Get the RGBA texture of the webcam.

int framerate()

Get the framerate of the webcam in frames per second.

int fps()

Get the framerate of the webcam in frames per second.

int width()

Get the width of the webcam in pixels.

int height()

Get the height of the webcam in pixels.

float aspect()

Get the aspect ratio of the webcam.

int deviceID()

Get the device id of this webcam.

string deviceName()

Get the user-friendly name of this webcam.

void capture(int capture)

Disable or enable webcam capture. If disabled, this webcam corresponding to this device id will stop reading new data and the webcam texture will not be updated.

int capture()

Get whether the webcam is capturing frames.

void freeze(int freeze)

Disable or enable webcam texture updates. If enabled, the webcam texture will not be updated with new data, but the webcam will continue to capture frames. Other webcam objects using the same device id will still be updated.

int freeze()

Get whether the webcam texture is frozen (not updating).