Get video resolution in nodes

I try to get an answer to this without actually finding any. Sorry if this sounds silly or obvious.

I have a nodejs application and basically I would just like to get the video resolution. Imagine I have a movie stored on disk and I would like to know if it is in 720p or 1080p or something else.

I realized that I might need to use ffmpeg for this, but then I also realized that ffmpeg is mainly used for "recording, converting and playing audio and video files." This does not mean obtaining video permission.

thanks for the help

Edit 1: The node.js application is a desktop application and should be portable on Linux, Windows, and OS X. If possible, a portable answer would be more appreciated, but of course, any answer would be welcome.

+5
source share
4 answers

Honestly, I think the best method I have found is to use fluent-ffmpeg with ffprobe, since you can specify the path to the executable. The only problem is that ffmpeg should come with the application. Thus, different executables must be sent, one for each distribution / os / origin. If anyone has something better, I am open to answers.

Getting the width, height, and aspect ratio using fluent-ffmpeg is done as follows:

var ffmpeg = require('fluent-ffmpeg'); ffmpeg.setFfprobePath(pathToFfprobeExecutable); ffmpeg.ffprobe(pathToYourVideo, function(err, metadata) { if (err) { console.error(err); } else { // metadata should contain 'width', 'height' and 'display_aspect_ratio' console.log(metadata); } }); 
+5
source

One way to do this is to run another application as a child process and get permission from std. I don't know about a clean node.js solution for this.

See child_process.exec https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

and ffprobe How to get permission (width and height) for a video file from linux command line?

+1
source

I use node -ffprobe to do this for images:

 var probe = require('/usr/lib/node_modules/node-ffprobe'); probe(filePath, function (err, data) { //the 'data' variable contains the information about the media file }); 
+1
source

There is an npm package called get-video-dimensions ffprobe which also uses ffprobe and is much easier to use. It also supports promises and async / await.

 import getDimensions from 'get-video-dimensions'; 

Using the 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); 
0
source

All Articles