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

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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