6

getUserMedia()我可以在浏览器中使用录制视频。但是,我还没有找到从浏览器向服务器提交(录制)或流式传输(实时)视频的便捷方法。

只有我发现将视频渲染到画布,然后提交或流式传输渲染的图像,例如通过数据 uri。(这是无效的。)

有没有更好的办法?(例如,直接流式传输二进制数据或将它们存储在文件中,然后发送此文件。)

更新:我发现了类似的老问题: Stream getUserMedia to an Icecast server?

4

2 回答 2

2

MediaStreamRecorder是一个用于记录 getUserMedia() 流的 WebRTC API。它允许 Web 应用程序从实时音频/视频会话创建文件。

 <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/

您可以将录制的文件发送到服务器。

于 2013-06-14T09:16:56.567 回答
0

它目前不是任何浏览器的一部分,但至少在 Chrome 中很快就会出现。检查http://code.google.com/p/chromium/issues/detail?id=113676

于 2013-07-03T14:13:53.777 回答