Chrome网络摄像头 - 保存录制内容

时间:2013-09-20 10:30:38

标签: javascript jquery html5 webcam

是否可以将视频流从网络摄像头保存到物理mp4文件?我想让用户在我们的网络应用程序中记录并发送视频。

到目前为止,我看到有人在做一个stream.record(),但这似乎不存在:

     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 sendXHR(){
      //Envia bien blob, no interpretado
      var xhr = new XMLHttpRequest();
      var video=$("#video");
      xhr.open('GET', video.src , true);
      xhr.responseType = 'blob';
      xhr.onload = function(e) {
      if (this.status == 200) {
          // Note: .response instead of .responseText
          var blob = new Blob([this.response], {type: 'video/webm'});
          console.log(blob.size/1024);
          console.log(blob.type);
          form = new FormData(),
          request = new XMLHttpRequest();
          form.append("myblob",blob,"Capture.webm");
          form.append("myname",$("#name_test").value);
          request.open("POST","./UploadServlet",true);
          request.send(form);
         }
      };
      xhr.send();
  }
    function startRecording() {
        sendXHR()
    }
    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.kongraju.in/uploadvideo.php", data, onUploadSuccess);
    }
    function onUploadSuccess() {
        alert ('video uploaded');
    }

webcamstream没有记录功能。

有没有人可能会有一个充满活力的例子?

0 个答案:

没有答案