6

I can record video using getUserMedia() in a browser. However, I have not find a convenient way to submit (recorded) or stream (live) video from browser to a server.

Only what I've found is to render video to canvas and then submit or stream rendered images e.g. by data uri. (Which is not effective.)

Is there a better way? (For instance, stream directly the binary data or store them in a file and then send this file.)

UPDATE: I have found similar old question: Stream getUserMedia to an Icecast server?

Community
  • 1
  • 1
TN.
  • 18,874
  • 30
  • 99
  • 157
  • 1
    See this: https://github.com/muaz-khan/WebRTC-Experiment/issues/8#issuecomment-19252169 You can get "Blob" object; then you can POST it via "FormData" and XMLHttpRequest. – Muaz Khan Jun 13 '13 at 01:11
  • You probably solved this already but I am having the same conundrum and the answer here looks promising: http://stackoverflow.com/questions/25523289/sending-a-mediastream-to-host-server-with-webrtc-after-it-is-captured-by-getuser – toraritte Feb 06 '17 at 02:14

2 Answers2

2

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/

you can send recorded file to server.

Thomas Potaire
  • 6,166
  • 36
  • 39
kongaraju
  • 9,344
  • 11
  • 55
  • 78
0

It is currently not part of any browser, but will be out soon at least in Chrome. Check http://code.google.com/p/chromium/issues/detail?id=113676

Vidhuran
  • 212
  • 4
  • 16