The problem appears simple, although I cannot find a suitable solution
because of my lack of knowledge of HTML and Javascript.
The task is simply to design a webpage where a button will activate the webcam and store either a still image or a video (preferable) in the local hard drive. No upload/download required for the time being.
After some attempts, I am able to use the getusermedia() api to activate the webcam and render the video in the browser window, but unable to save it. This is what my code looks like.
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
}
So any idea on how to save either a still image or a video in the hard drive captured the same way?
Best Answer
First, the
navigator.getUserMedia
API is being deprecated, you should now use thenavigator.mediaDevices.getUserMedia
method.Then to take a still image, you can indeed use a canvas which can draw a video element.
As a fiddle since Stacksnippets may block gUM requests...
And to save as a video, you can use the [MediaRecorder API](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorderà, which will allow you to save a MediaStream as webm:
And as a fiddle
Notes:
The MediaRecorder API is still a quite new API and there are still some bugs in the [little set of browser implementations.