RecordRTC - 用mic + visual创建视频?

时间:2017-05-09 12:24:46

标签: recordrtc

是否可以结合'画布'录音机和音频' RecordRTC中的录像机功能可以创建单个.webm视频,其中画布动画为视频,麦克风输入为音频?

1 个答案:

答案 0 :(得分:1)

是的。您可以将canvas-2d和麦克风录制到单个WebM容器中。

navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
navigator.getUserMedia({
    audio: true
}, funtion(microphone) {
    var canvasStream = canvas.captureStream(25);
    microphone.getAudioTracks().forEach(function(track) {
        // merge microphone into canvas stream
        canvasStream.addTrack(track);
    });

    // now your canvas stream has both audio and video tracks
    // now you can record it using RecordRTC
    var recorder = RecordRTC(canvasStream, {
        type: 'video'
    });

    // auto stop after 5 seconds recording
    recorder.setRecordingDuration(5 * 1000).onRecordingStopped(function() {
        var url = recorder.toURL();
        window.open(url);

        var blob = recorder.getBlob();
        var singleWebM = new File([blob], 'single.webm', {
            type: 'video/webm'
        });
    });

    recorder.startRecording();
}, function(error) {
    alert('unable to access your microphone');

});

有关详情,请查看:WebRTC captureStream API