Reference createCapture()

createCapture()

Creates a <video></video> element that "captures" the audio/video stream from the webcam and microphone.

createCapture() returns a new p5.MediaElement object. Videos are shown by default. They can be hidden by calling capture.hide() and drawn to the canvas using image().

The first parameter, type, is optional. It sets the type of capture to use. By default, createCapture() captures both audio and video. If VIDEO is passed, as in createCapture(VIDEO), only video will be captured. If AUDIO is passed, as in createCapture(AUDIO), only audio will be captured. A constraints object can also be passed to customize the stream. See the W3C documentation for possible properties. Different browsers support different properties.

The 'flipped' property is an optional property which can be set to {flipped:true} to mirror the video output.If it is true then it means that video will be mirrored or flipped and if nothing is mentioned then by default it will be false.

The second parameter,callback, is optional. It's a function to call once the capture is ready for use. The callback function should have one parameter, stream, that's a MediaStream object.

Note: createCapture() only works when running a sketch locally or using HTTPS. Learn more here and here.

Examples

Syntax

createCapture([type], [flipped], [callback])

Parameters

type
String|Constant|Object:

type of capture, either AUDIO or VIDEO, or a constraints object. Both video and audio audio streams are captured by default.

flipped
Object:

flip the capturing video and mirror the output with {flipped:true}. By default it is false.

callback
Function:

function to call once the stream has loaded.

Returns

p5.MediaElement: new p5.MediaElement object.
Notice any errors or typos? Please let us know. Please feel free to edit src/dom/dom.js and open a pull request!

Related References