【问题标题】:Is there a way using ffprobe (fluent-ffmpeg) input with a read stream in node.js?有没有办法在node.js中使用带有读取流的ffprobe(fluent-ffmpeg)输入?
【发布时间】:2020-06-23 00:26:13
【问题描述】:

我在我的代码中使用 fluent-ffmpeg,我的主要目标是获取音频/视频持续时间, 我需要使用流作为输入。

根据文件, https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#reading-video-metadata

ffmpeg('/path/to/file1.avi')
  .input('/path/to/file2.avi')
  .ffprobe(function(err, data) {
    console.log('file2 metadata:');
    console.dir(data);
  });

ffmpeg('/path/to/file1.avi')
  .input('/path/to/file2.avi')
  .ffprobe(0, function(err, data) {
    console.log('file1 metadata:');
    console.dir(data);
  });

这些我都试过了

const ffmpeg = require('fluent-ffmpeg')
const fs = require('fs')

filepath = './scratch_file/assets_audios_10000.wav'
stream = fs.createReadStream(filepath)
ffmpeg(stream)
.input(filepath) // have to put a file path here, possible path dependent
.ffprobe(function (err, metadata) {
    if (err){throw err}
    console.log(metadata.format.duration);
}) //success printing the duration 

以上成功返回时长

ffmpeg(stream)
.input(stream) //
.ffprobe(function (err, metadata) {
    if (err){throw err}
    console.log(metadata.format.duration);
}) // failed

以上失败。

ffmpeg(stream)
.ffprobe(function (err, metadata) {
    if (err){throw err}
    console.log(metadata.format.duration);
}) //returned "N/A"

返回不适用

有人可以帮忙吗?我需要类似的东西

ffmpeg.ffprobe(stream, (metadata) => {console.log(metadata.format.duration)} )

谢谢。

【问题讨论】:

    标签: node.js video ffmpeg


    【解决方案1】:

    以下代码对我有用。

      let ffmpeg = require('fluent-ffmpeg')
    
      // create a new readable stream from whatever buffer you have
      let readStream = new Readable()
      readStream._read = () => {}
      readStream.push(imageBufferObject.buffer)
      readStream.push(null)
    
     // I used a call to a promise based function to await the response
     let metadata = await get_video_meta_data(readStream)
     console.log(metadata)
    
     async function get_video_meta_data(stream){
      return new Promise((resolve, reject)=>{
        ffmpeg.ffprobe(stream, (err, meta)=>{
          resolve(meta)
        })
     })
    

    }

    只需将可读流输入到 ffmpeg.ffprobe() 中,它期望文件路径似乎对我有用,因为我可以在不写入磁盘的情况下提取元数据。

    【讨论】:

      猜你喜欢
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 2015-09-20
      • 2011-12-11
      • 2017-12-10
      • 1970-01-01
      相关资源
      最近更新 更多