Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!