How to write a blob which contains chanks of video and audio?

34 Views Asked by At

The front side sends me a chunk of data from the media recorder method so when the audio and video are sent to the socket, I can record properly but when the user stops the camera or audio from the part which the first time streams has only one type of data it recorded to file but the remaining parts which have been changed is not in video or audio.

//the data may be audio or video according to media recorder which one recorded

    this.mediaRecorder.ondataavailable = async function(e) {
      socket.emit('recordVideo', e.data);

//in the backend I used an array to store the stream

  async sendVideoParts(parts, name) {
    console.log("stop record!");
  
    const blob = new Blob(parts, { type: 'video/mp4' })
    const buffer = Buffer.from( await blob.arrayBuffer() );
    fs.writeFile(`${name}video.mp4`, buffer, () => console.log('video saved!') );
  
    this.challengerVideo = []
    this.challengeeVideo = []
    this.challengee=""
    this.challenger=""

  }

in the above code when the first time stream contains audio and video or one of them it produces a video but the time at which audio or video is pushed in the array doesn't show in the final file. for example: from time 0 to 8 seconds when audio and video exist the file also has from the second 8 which the audio stops from the front it doesn't exist in the final file.

0

There are 0 best solutions below