muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.56k stars 1.76k forks source link

Lose milliseconds during interval stop/start recording #698

Open mohamedale opened 3 years ago

mohamedale commented 3 years ago

i'have a live streaming and i want to record this stream as a pices then bind all pices as one video, i follow the interval method (stop/start recording) to make many of videos for upload to my server then bind all in one video but during stop/start recording i lose milliseconds between record and another, which makes the final video inconvenient.

let counter = 1,
    recorder,
navigator.mediaDevices.getUserMedia({
    video: true,
    audio: true
}).then(function(stream) {
    (async function lopper() {
        recorder = RecordRTC(stream, {
            type: 'video',
            mimeType: 'video/webm;codecs=vp9',
            recorderType: MediaStreamRecorder,
            disableLogs: true,
        });
        recorder.startRecording();

        const sleep = m => new Promise(r => setTimeout(r, m));
        await sleep(3000);

        recorder.stopRecording(function() {
            let blob        = recorder.getBlob()
                formData    = new FormData();
            formData.append('file', blob, 'file_'+counter+'.webm');

            $.ajax({
                url: '/path/to/upload-live-stream',
                method: 'POST',
                data: formData,
                async: true,
                dataType: 'json',
                contentType: false,
                processData: false,
                success: function (data) {
                    console.log(data)
                },

            })

            lopper()
            counter++
        });
    })();
}).catch((msg)=>{
    console.error(msg)
});

this is my problem and my code at stackoverflow: https://stackoverflow.com/questions/64685165/interval-video-recording-with-recordrtc @muaz-khan