Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda