Skip to content

Instantly share code, notes, and snippets.

@drslump
Created May 4, 2020 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drslump/8b979a01d2a1313af143276528c4278a to your computer and use it in GitHub Desktop.
Save drslump/8b979a01d2a1313af143276528c4278a to your computer and use it in GitHub Desktop.
ImageCapture, ImageBitmap and canvas
// The theory is that we can avoid moving the video data into RAM since we are only
// passing the ImagieBitmap reference around, which should improve the performance when
// plotting captured frames.
const stream = await navigator.mediaDevices.getUserMedia({video: true})
const [track] = stream.getVideoTracks()
const ic = new ImageCapture(track)
const bmp = await ic.grabFrame()
const canvas = document.createElement('canvas')
// We can't draw on this context though!
const ctx = canvas.getContext('bitmaprenderer')
ctx.transferFromImageBitmap(bmp);
// Now we can place the canvas on the DOM where and whenever needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment