Function frames

  • Generator that yields frames from a video element as ImageData.

    import { Video } from 'https://unpkg.com/ixfx/dist/visual.js'

    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);
    }

    Under the hood it creates a hidden canvas where frames are drawn to. This is necessary to read back pixel data. An existing canvas can be used if it is passed in as an option.

    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)

    Parameters

    • sourceVideoEl: HTMLVideoElement
    • opts: FramesOpts = {}

    Returns AsyncIterable<ImageData>