// Capture from a VIDEO element, handling frame data // imageData is ImageData type: https://developer.mozilla.org/en-US/docs/Web/API/ImageData Video.capture(sourceVideoEl, { onFrame(imageData => { // Do something with pixels... }); });
canvasEl: CANVAS element to use as a buffer (optional)
maxIntervalMs: Max frame rate (0 by default, ie runs as fast as possible)
showCanvas: Whether buffer canvas will be shown (false by default)
workerScript: If this specified, this URL will be loaded as a Worker, and frame data will be automatically posted to it
Implementation: frames are captured using a animation-speed loop to a hidden canvas. From there
the pixel data is extracted and sent to either destination. In future the intermediate drawing to a
canvas could be skipped if it becomes possible to get pixel data from an ImageBitmap.
Captures frames from a video element. It can send pixel data to a function or post to a worker script.
Example: Using a function
Example: Using a worker
In frameProcessor.js:
Options:
canvasEl
: CANVAS element to use as a buffer (optional)maxIntervalMs
: Max frame rate (0 by default, ie runs as fast as possible)showCanvas
: Whether buffer canvas will be shown (false by default)workerScript
: If this specified, this URL will be loaded as a Worker, and frame data will be automatically posted to itImplementation: frames are captured using a animation-speed loop to a hidden canvas. From there the pixel data is extracted and sent to either destination. In future the intermediate drawing to a canvas could be skipped if it becomes possible to get pixel data from an ImageBitmap.