RecordRTC audio subsequent tracks

37 Views Asked by At

I implemented the video recording, it initially starts like this:

mediaRecorder = new RecordRTCPromisesHandler([remoteAudioStream, remoteVideoStream], {
   mimeType: 'video/webm', // vp8, vp9, h264, mkv, opus/vorbis
   audioBitsPerSecond : 256 * 8 * 1024,
   videoBitsPerSecond : 256 * 8 * 1024,
   bitsPerSecond: 256 * 8 * 1024,  // if this is provided, skip above two
   checkForInactiveTracks: true,
   timeSlice: 1000, // concatenate intervals based blobs
   ondataavailable: function(data) { console.log(' ondataavailable', data);}, // get intervals based blobs
   enable: { video: true, audio: true }
});

mediaRecorder.startRecording();

When we receive a new VIDEO stream, initially or after closing and starting the stream, we have this handler for adding the stream.

async function consumeVideo(videoParams) {
  remoteVideoStream.addTrack(await getVideoTrack(videoParams));
  addStream({ htmlElement: remoteVideo, stream: remoteVideoStream });
}
const getVideoTrack = async (videoParams) => {
  consumerVideo = await consumerTransport.consume({
    id: videoParams.id,
    producerId: videoParams.producerId,
    kind: videoParams.kind,
    rtpParameters: videoParams.rtpParameters,
  });

  consumerVideo.on('transportclose', () => {
    console.log('transport closed so consumer closed');
  });

  return consumerVideo.track;
};

When closing the record, for its download we have this:

   await mediaRecorder?.stopRecording();
   const blob = await mediaRecorder?.getBlob();
   invokeSaveAsDialog(blob, `${generateUUID()}.mp4`);

For video it works perfectly, when the recorder is ON and the client starts the camera, we enter the consumeVideo handler and add the track, when the client stops and restarts the camera, the new track is added(consumeVideo is called again).

The downloaded record includes the recorded videos, and during the period between the records there is a black screen as expected because the record does not stop until the end.

I have the problem with the audio recording part, unlike the video, when the client stops the stream and restarts it, the final downloaded record does not include the audio records after the first audio.

So the final file will contain the video that can be composed of several parts and ONLY the first audio record(until it was stopped the first time).

0

There are 0 best solutions below