Video
Module Visual.Video
This module has two functions for reading frames. Video.frames gives generator-style access, Video.capture gives callback-style access.
Both give back frames as ImageData
. See Image Data for tips on how to read pixel values from these objects.
In both cases, you can use the maxIntervalMs
option to set the speed at which frames are read. By default the value is 0, reading as fast as possible. If you’re doing heavy processing, you may want to increase this value to not overload your device.
Frames
Section titled “Frames”Video.frames returns frames as a generator.
import { Video } from 'https://unpkg.com/@ixfx/visual/bundle'
const ctx = canvasEl.getContext(`2d`);for await (const frame of Video.frames(videoEl)) { // TODO: Some processing of pixels
// Draw image on to the visible canvas ctx.putImageData(frame, 0, 0);}
Capture
Section titled “Capture”Video.capture returns frames to a callback function.
import { Video } from 'https://unpkg.com/@ixfx/visual/bundle'
// Capture from a VIDEO element, handling frame dataVideo.capture(sourceVideoEl, { onFrame(imageData => { // Do something with pixels... });});
Importing
Section titled “Importing”// Sub moduleimport { Video } from "@ixfx/visual.js"// Eg: Video.frames();
// Whole moduleimport * as Visual from "@ixfx/visual.js"// Eg: Visual.Video.frames();
// From bundleimport { Visual } from "@ixfx"// Eg: Visual.Video.frames();
// And within your HTML's <HEAD> </HEAD> block:<script type="importmap">{ "imports": { "@ixfx":"/ixfx/index.js", "@ixfx/": "/ixfx/" } }</script>
// Sub module from parentimport { Video } from "@ixfx/visual.js"// Eg: Video.frames();
// Whole parent moduleimport * as Visual from "@ixfx/visual.js"// Eg: Visual.Video.frames();
// From the bundleimport { Visual } from "@ixfx/bundle.js"// Eg: Visual.Video.frames();
// Sub module from parentimport { Video } from "https://unpkg.com/@ixfx/visual/bundle"// Eg: Video.frames();
// Whole parent moduleimport * as Visual from "https://unpkg.com/@ixfx/visual/bundle"// Eg: Visual.Video.frames();
// Single module from the bundleimport { Visual } from "https://unpkg.com/@ixfx/bundle"// Eg: Visual.Video.frames();