【问题标题】:Using node fluent-ffmpeg for converting images to video使用 node fluent-ffmpeg 将图像转换为视频
【发布时间】:2017-11-10 06:25:53
【问题描述】:

我为此找到了很多示例,但没有一个适合我。

我有几张图片。 URL、Base64 或缓冲区。

我需要在不改变质量的情况下将它们转换成视频。

我最接近的是这个命令:
ffmpeg -framerate 1 pattern_type glob -i 'images/*.jpg' -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

但它每秒显示 1 张图像。我需要视频为 30fps,而不是 1 张 30 帧的图像,而是每秒 30 张图像。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: node.js video ffmpeg fluent-ffmpeg


    【解决方案1】:

    我最终使用了不同的包 - ffmpeg-stream

    我是从 AWS 获取图像,所以下面有一些 AWS 代码:

    const frames = ['frame1.jpg', 'frame2.jpg', ...]
    
    const conv = ffmpeg() // create converter
    const input = conv.input({f: 'image2pipe', r: 30}) // create input writable stream
    conv.output('out.mp4', {vcodec: 'libx264', pix_fmt: 'yuv420p'}) // output to file
    
    // for every frame create a function that returns a promise
    frames.map(filename => () =>
      new Promise((fulfill, reject) =>
        s3
          .getObject({Bucket: '...', Key: filename})
          .createReadStream()
          .on('end', fulfill) // fulfill promise on frame end
          .on('error', reject) // reject promise on error
          .pipe(input, {end: false}) // pipe to converter, but don't end the input yet
      )
    )
    // reduce into a single promise, run sequentially
    .reduce((prev, next) => prev.then(next), Promise.resolve())
    // end converter input
    .then(() => input.end())
    
    conv.run()
    

    这是我在 github repo 上发布的问题: https://github.com/phaux/node-ffmpeg-stream/issues/5

    【讨论】:

      猜你喜欢
      • 2014-03-02
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      相关资源
      最近更新 更多