/  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

dur duration()

Get total length of the file as a duration.

float fps()

Get the framerate of the video.

float framerate()

Get the framerate of the video.

int height()

Get the height of the video in texels.

int loop()

Get whether the video is looping. Default false.

void loop(int loop)

Set whether the video should loop. Default false.

int mode()

Get the texture conversion mode for this video.

void mode(int mode)

Set the texture conversion mode for this video. Valid values are Video.MODE_RGBA and Video.MODE_YCRCB. Defaults to Video.MODE_RGBA,which converts the decoded video YCrCb planes into into rgba format and writes them to the rgba texture, accessible via Video.texture(). However, this YCrCb-->RGBA conversion is very costly (taking as much time as all the other video decodings steps combined). Setting Video.MODE_YCRCB will skip this costly conversion steps and write the individual planes to their own textures, Video.textureY(), Video.textureCr(), Video.textureCb(), where they may be sampled and converted in parallel on a shader. See examples/deep/video-ycrcb.ck for an demonstration of how to do so.

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.

float 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 samplerate()

Get the samplerate of the video's audio stream.

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.

Texture texture()

Get the RGBA texture of the video. Only updated if Video.mode() == Video.MODE_RGBA.

Texture textureCb()

Get the decoded Cb chroma plane of the video. Only updated if Video.mode() == Video.MODE_YCRCB.

Texture textureCr()

Get the decoded Cr chroma plane of the video. Only updated if Video.mode() == Video.MODE_YCRCB.

Texture textureY()

Get the decoded Luma plane of the video. Only updated if Video.mode() == Video.MODE_YCRCB.

dur timestamp()

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

int width()

Get the width of the video in texels.

static member variables

int MODE_RGBA

The default mode. Equals 0. The raw YCrCb video data is converted to RGBA on the CPU.

int MODE_YCRCB

Equals 1. Copies the raw YCrCb video data directly to the video textures. Significantly reduces CPU overhead, but conversion must happen in a shader.


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

float aspect()

Get the aspect ratio of the 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.

int deviceID()

Get the device id of this webcam.

string deviceName()

Get the user-friendly name of this webcam.

int fps()

Get the framerate of the webcam in frames per second.

int framerate()

Get the framerate of the webcam in frames per second.

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).

int height()

Get the height of the webcam in pixels.

Texture texture()

Get the RGBA texture of the webcam.

int width()

Get the width of the webcam in pixels.