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

175
Views
How can I determine the width and height of a video without going through the DOM?

If I want to determine the width and height of an image, I can do the following:

let image = new Image();
image.src = ...the source ;
image.decode();

console.log( image.width, image.height );

There is no need to create a DOM element to render the image and then obtain the the dimensions.

Is it possible to do something similar with a video? If so, how?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This seems to do what I want:

let video = document.createElement( 'video');

video.setAttribute( "preload", "metadata" );

video.src = // ...the data source

video.addEventListener( 'loadeddata', function() {
    console.log( this.videoWidth, this.videoHeight );

});

I create the video element, but do not insert it into the DOM. I believe setting the preload attribute does not require the entire video file to be loaded, but I am not certain about that.

The data is loaded and the loadeddata event is triggered, logging the width and height of the video.

I would be interested in knowing what other people thought about this solution.

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!