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

162
Views
How can I get video bitrate with javascript

I want to get the bitrate of video that uploader, because the backend need it.

var video = document.createElement('video');
video.preload = 'metadata';
video.src = URL.createObjectURL(document.getElementById('fileUp').files[0]);
window.URL.revokeObjectURL(video.src);
console.log(video.bitrate);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can get the video duration then simply divide the file size by it to get an approximation (subtitles, audio and metadata would also be included in this value), as far as i know there is no standard api for getting the bitrate directly.

Example (credits https://stackoverflow.com/a/67899188/6072029 ) :

<div>
    <script>
        const getVideoInfos = (file) =>
            new Promise((resolve, reject) => {
                const reader = new FileReader();
                reader.onload = () => {
                    const media = new Audio(reader.result);
                    media.onloadedmetadata = () => resolve({
                        duration: media.duration,
                        file_size: file.size,
                        bitrate: file.size / media.duration,
                    });
                };
                reader.readAsDataURL(file);
                reader.onerror = (error) => reject(error);
            });

        const handleChange = async (e) => {
            const infos = await getVideoInfos(e.target.files[0]);
            document.querySelector("#infos").innerText = `Infos : ${JSON.stringify(infos, null, 4)}`;
        };


    </script>
    <input type="file" onchange="handleChange(event)" />
    <p id="infos">infos: </p>
</div>
about 4 years ago · Juan Pablo Isaza Report
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!