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

71
Views
Problem while converting a Video file to Webm using MediaRecorder api

I am trying to use MediaRecorder API to convert my video to webm. However after following some online examples, I am still not able to figure out how to do that.

Here is the main exceprt from my code:

convertVideo = (e)=>{
        //creating a virtual video element
        const virtualVideo = document.createElement("video");

        //this file is File Blob I get from user input. I have checked it is all good and has data.
        virtualVideo.src = URL.createObjectURL(this.file);
        virtualVideo.muted=true;

        virtualVideo.oncanplay=e=>{
            console.log("Can play");
            virtualVideo.play();
        }
        
        virtualVideo.onplay=()=>{
            console.log("Playing");
            const stream = virtualVideo.captureStream();
            const recorder = new MediaRecorder(stream);
            
            const data=[];
            recorder.ondataavailable = e=>data.push(e.data);
            recorder.start();

            recorder.onstop=()=>{
                console.log("Stopped recording");
                const blob = new Blob(data,{mimeType:"video/webm"});
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'test.webm';
                a.click();
                URL.revokeObjectURL(url);
            }

            virtualVideo.onended=(e)=>{
                console.log("video ended");
                recorder.stop();
            }
        }

    }

The data array is always empty. Can't figure out what I a doing wrong.

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!