TIL about the Image Capture API
POSTED ON:
TAGS: browser apis javascript
The Image Capture API which helps us to capture an image or grab a frame from the video devices(like webcam). Not only that, you can also perform actions on capturing an image or grabbing a frame.
NOTE: The end user does need to give the code permission to do so.
navigator.mediaDevices.getUserMedia({video: true})
.then(mediaStream => {
document.querySelector('video').srcObject = mediaStream;
const track = mediaStream.getVideoTracks()[0];
setTrack(track);
}).catch(error => {
console.error(` ${error} is not yet supported`);
setError(error);
});
In the blog post, there's also other use-cases.
Like taking screenshots, or streaming the video.
You can check out the demo: https://demo.greenroots.info/web-apis/web-apis-image-capture/
via Tapas Adhikary's 10 lesser-known Web APIs you may want to use
Related TILs
Tagged: browser