【问题标题】:use node-video-lib with buffer使用带缓冲区的 node-video-lib
【发布时间】:2021-05-20 07:28:38
【问题描述】:

我正在尝试使用库 node-video-lib 并获取有关服务器上收到的视频的信息, 但是在文档中,我看到了仅使用文件系统中的文件的示例,

这是文档中的示例:

const fs = require('fs');
const VideoLib = require('node-video-lib');

fs.open('/path/to/file', 'r', function(err, fd) {
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        // Work with movie
        console.log('Duration:', movie.relativeDuration());
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});

我的问题:我怎样才能像例子中那样得到 fd 号码,

fs.open('/path/to/file', 'r', function(err, fd)

来自文件缓冲区?

类似这样的:

const VideoLib = require('node-video-lib');

    app.post(route + '/upload', (req, response) => {
        let file = req.files.file;
        let buffer=file.data;
        let fd=?
    try {
        let movie = VideoLib.MovieParser.parse(fd);
        // Work with movie
        console.log('Duration:', movie.relativeDuration());
    } catch (ex) {
        console.error('Error:', ex);
    } finally {
        fs.closeSync(fd);
    }
});
  });

在从 videoLib 获取信息之前,我必须将文件 - 我的视频写入我的文件系统吗?

【问题讨论】:

    标签: node.js npm video readfile video-library


    【解决方案1】:

    VideoLib.MovieParser.parse 方法接受文件处理程序或缓冲区参数:

    https://github.com/gkozlenko/node-video-lib#movieparser

    因此您可以根据您提供的代码将file.databuffer 传递给此方法,如下所示:

    app.post(route + '/upload', (req, response) => {
        let file = req.files.file;
        let buffer = file.data;
        try {
            let movie = VideoLib.MovieParser.parse(buffer);
            // Work with movie
            console.log('Duration:', movie.relativeDuration());
        } catch (ex) {
            console.error('Error:', ex);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2015-01-12
      • 1970-01-01
      • 2012-01-05
      • 2017-12-08
      • 1970-01-01
      • 2019-12-08
      相关资源
      最近更新 更多