HTML5 video recording


Question

I would like to create a simple video streaming app by using HTML5 features + Node.js on the server side (actually I am not sure this is possible...). Now I have some important questions:

  • Is it possible to record the local stream created by the navigator.getUserMedia() API? I read lots of articles but everywhere it is just used to define the source of a HTML5 video element.
  • Is it possible to send this stream through websockets? (socket.io, binaryjs,... ?). Otherwise I can only imagine sending frames to a canvas element, and I am not sure that is a good solution.
  • Is there any Node.js module that supports load balancing? It would be interesting to work with different node servers.

Thank you all in advance.

1
1
10/8/2012 5:59:20 PM

MediaStreamRecorder is a WebRTC API for recording getUserMedia() streams . It allows web apps to create a file from a live audio/video session.

 <video autoplay></video>

    <script language="javascript" type="text/javascript">
    function onVideoFail(e) {
        console.log('webcam fail!', e);
      };

    function hasGetUserMedia() {
      // Note: Opera is unprefixed.
      return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
                navigator.mozGetUserMedia || navigator.msGetUserMedia);
    }

    if (hasGetUserMedia()) {
      // Good to go!
    } else {
      alert('getUserMedia() is not supported in your browser');
    }

    window.URL = window.URL || window.webkitURL;
    navigator.getUserMedia  = navigator.getUserMedia || 
                             navigator.webkitGetUserMedia ||
                              navigator.mozGetUserMedia || 
                               navigator.msGetUserMedia;

    var video = document.querySelector('video');
    var streamRecorder;
    var webcamstream;

    if (navigator.getUserMedia) {
      navigator.getUserMedia({audio: true, video: true}, function(stream) {
        video.src = window.URL.createObjectURL(stream);
        webcamstream = stream;
    //  streamrecorder = webcamstream.record();
      }, onVideoFail);
    } else {
        alert ('failed');
    }

    function startRecording() {
        streamRecorder = webcamstream.record();
        setTimeout(stopRecording, 10000);
    }
    function stopRecording() {
        streamRecorder.getRecordedData(postVideoToServer);
    }
    function postVideoToServer(videoblob) {

        var data = {};
        data.video = videoblob;
        data.metadata = 'test metadata';
        data.action = "upload_video";
        jQuery.post("http://www.foundthru.co.uk/uploadvideo.php", data, onUploadSuccess);
    }
    function onUploadSuccess() {
        alert ('video uploaded');
    }

    </script>

    <div id="webcamcontrols">
        <button class="recordbutton" onclick="startRecording();">RECORD</button>
    </div>

http://www.w3.org/TR/mediastream-recording/

Update:

MediaElements have to new method to capture streams, have a look at below article

https://developers.google.com/web/updates/2016/10/capture-stream

2
4/14/2017 10:18:55 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon