记录RTC | 我们可以在不stopRecording的情况下保存blob数据吗

Sau*_*rma 5 video-capture video-streaming html5-video recordrtc

我正在使用 RecordRTC 并尝试每 1 分钟保存一次视频,但为了保存视频,我必须调用 stopRecording()。例如:

function postFiles() {
            var blob = recorder.getBlob();
            // getting unique identifier for the file name
            var fileName = generateRandomString() + '.webm';

            var file = new File([blob], fileName, {
                type: 'video/webm'
            });

            xhr('/uploadFile', file, function(responseText) {
                    console.log(responseText);
            });

            if(mediaStream) mediaStream.stop();
        }

stopRecording(postFiles);
Run Code Online (Sandbox Code Playgroud)

我想在不停止录制的情况下保存视频。

Mua*_*han 4

相关演示:https://www.webrtc-experiment.com/RecordRTC/simple-demos/ondataavailable.html

recorder = RecordRTC(camera, {
    recorderType: MediaStreamRecorder,
    mimeType: 'video/webm',
    timeSlice: 1000, // pass this parameter
    ondataavailable: function(blob) {
        invokeSaveAsDialog(blob);
    }
});
Run Code Online (Sandbox Code Playgroud)

如您所见,我传递了两个附加参数:

  1. ondataavailable回调函数
  2. timeSlice间隔

ondataavailable将在每个指定的时间间隔后返回 blob。

  • @Muaz Khan 尝试了相同的方法,但正确保存了第一个视频块,而其余的块则无法正确保存。他们甚至根本不玩。有什么解决办法吗? (2认同)