Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert a MediaStream to a video blob with html5

I am trying to capture a 5 minute long video from a web cam in a website.

I am currently using an html5 video element to display the getUserMedia result stream.

Is there anyway for me to get the contents of the stream once I finished with the recording?

I am left with a MediaStream object, and I guess it contains the video blob, can I access it somehow?

like image 615
Remoba Avatar asked Nov 11 '22 00:11

Remoba


2 Answers

Saving a blob

const saveBlob = (function() {
  const a = document.createElement('a');
  document.body.appendChild(a);
  a.style.display = 'none';
  return function saveData(blob, fileName) {
     const url = window.URL.createObjectURL(blob);
     a.href = url;
     a.download = fileName;
     a.click();
  };
}());

Usage: saveBlob(someBlob, 'filename');

Note: S.O. snippets blocks downloading so here's a runnable version

https://jsgist.org/?src=fe37a11d207f0f83a877e0c0252539c2

like image 84
gman Avatar answered Nov 14 '22 21:11

gman


You could encode the video as a data URI and add a download link.

http://appcropolis.com/blog/web-technology/using-html5-canvas-to-capture-frames-from-a-video/ http://www.iandevlin.com/blog/2012/09/html5/html5-media-and-data-uri

like image 40
urnotmydad Avatar answered Nov 14 '22 21:11

urnotmydad