HTML5 video recording

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.

You can record video using RecordRTC. Here a Demo.

You can use "MediaSource" APIs to capture pre-recorded media from video-element; get array buffer / blob / unit8Array and upload that array (chunks) using XMLHttpRequest or other methods.

You can send those "cunks" via WebSocket/Socet.io/Firebase/etc. for realtime streaming without using RTCWeb APIs!!!! Though, there are so many pitfalls: A huge typed array. A big data to be transferred. Also, these APIs works only with HTML5 video element. A limited support on Chrome Canary and Firefox.

Good news is that MediaSource APIs plays video as soon as it gets first chunk. It not waits for whole video/data to be downloaded before playing video.

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/