Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
upload media recorder video to express server

I am working on an Electron app where I'm recording video using MediaRecorder API and posting buffer to the server with 5 seconds timeslice.


let recordedChunks = [];
const startBtn = document.getElementById('startBtn');
startBtn.onclick = e => {

  // Create the Media Recorder
  const options = { mimeType: 'video/webm; codecs=vp9' };
  mediaRecorder = new MediaRecorder(stream, options);

  mediaRecorder.ondataavailable = handleDataAvailable;
  mediaRecorder.onstop = handleStop;

  mediaRecorder.start(timeslice);    // timeslice being 5000

}

// handling available data 
function handleDataAvailable(e) {
  recordedChunks.push(e.data);
  var blob = new Blob(recordedChunks, {
    type: 'video/webm; codecs=vp9'
  });

  var buffer = Buffer.from(await blob.arrayBuffer());

  var data = { video_buffer: buffer};
  
  // for posting buffer to the server
  axios.post(API + '/video/', data, {
     observe: 'body',
     withCredentials: true,
   })
     .then((res) => {
       console.log(`Status: ${res.status}`);
       console.log('Body: ', res.data);
     }).catch((err) => {
       console.error(err);
     });
  
  recordedChunks = [];
}

And on my Express server, I'm handling the above buffer like this

const videoView = (req, res) => {
  const buffer = Buffer.from(req.body.video_buffer);

  const stored_stream = fs.createWriteStream('video.webm', { 'flags': 'a' });
    stored_stream.write(buffer);

    res.end(JSON.stringify({ 'success': true }))
}

The above code is working fine except for some cases that I don't know of.

Sometimes the recorded video on the server is incomplete or the frames freeze in between, and sometimes the video is completely corrupted but the video size is the same as that of the local video (since I'm also saving the same video locally and the local video plays fine every time.).

I'm using Electron@17.1.1 on Windows 10 with a good internet connection.

Any help would be appreciated as I don't have much experience working with JavaScript Streams.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda