Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get video resolution in nodejs

I have been trying to get an answer to this without really finding any. Excuse me if this sounds stupid or obvious.

I have a nodejs application and basically I would like to simply get the resolution of a video. Imagine I have film stored on disk and I would like to be able to know if it is in 720p or 1080p or anything else.

I understood that I might need to use ffmpeg to do so, but then I also understood that ffmpeg was mostly used to "record, convert and stream audio and video files". That does not mean retrieve video resolution.

Thank you for your help

Edit 1: The node.js app is a desktop app and needs to be portable to Linux, windows and OS X. If possible a portable answer would be more appreciated but of course any answer is welcome.

like image 637
tgdn Avatar asked Aug 10 '15 16:08

tgdn


1 Answers

There's a npm package called get-video-dimensions that also use ffprobe and it's much easier to use. It also support promises and async/await.

import getDimensions from 'get-video-dimensions';

Using promise:

getDimensions('video.mp4').then(dimensions => {
  console.log(dimensions.width);
  console.log(dimensions.height);
})

or async/await:

const dimensions = await getDimensions('video.mp4');
console.log(dimensions.width);
console.log(dimensions.height);
like image 104
Sinandro Avatar answered Sep 22 '22 22:09

Sinandro