在nodejs中获取视频分辨率 [英] Get video resolution in nodejs

查看:2448
本文介绍了在nodejs中获取视频分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图得到一个答案,而没有找到任何。对不起,如果这听起来很愚蠢或明显。



我有一个nodejs应用程序,基本上我只想得到一个视频的分辨率。想象一下,我将电影存储在磁盘上,我想知道是720p还是1080p或其他任何东西。



我明白,我可能需要使用ffmpeg这样做,但是我也明白,ffmpeg主要用于录制,转换和流式传输音频和视频文件 。
这并不意味着检索视频分辨率。



感谢您的帮助



编辑1:
node.js应用程序是一个桌面应用程序,需要移植到Linux,Windows和OS X.如果可能,便携式答案将会更受赞赏,但当然任何答案都是值得欢迎的。

解决方案

说实话,我觉得最好的方法是使用流利的 - ffmpeg 与ffprobe,因为您可以设置可执行文件的路径。唯一的问题是ffmpeg必须随应用程序一起提供。所以不同的可执行文件必须发货,每个分发/ os /派生一个。如果任何人有更好的东西,我可以回答。



使用流畅的ffmpeg获取宽度,高度和宽高比是这样完成的:

  var ffmpeg = require('fluent-ffmpeg'); 

ffmpeg.setFfprobePath(pathToFfprobeExecutable);

ffmpeg.ffprobe(pathToYourVideo,function(err,metadata){
if(err){
console.error(err);
} else {
//元数据应包含'width','height'和'display_aspect_ratio'
console.log(元数据);
}
});


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.

解决方案

To be honest I think the best method I found was to use fluent-ffmpeg with ffprobe as you are able to set the the path to the executable. The only problem is that ffmpeg has to be shipped with the app. So different executables have to be shipped, one for each distribution/os/derivation. If anyone has anything better I am open to answers.

Getting the width, height and aspect ratio using fluent-ffmpeg is done like so:

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);
    }
});

这篇关于在nodejs中获取视频分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆