Created
May 4, 2020 08:54
-
-
Save drslump/8b979a01d2a1313af143276528c4278a to your computer and use it in GitHub Desktop.
ImageCapture, ImageBitmap and canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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