【问题标题】:NodeJS spawn ffmpeg thumb %t in filenameNodeJS 在文件名中生成 ffmpeg thumb %t
【发布时间】:2017-09-06 16:58:47
【问题描述】:

我正在使用此 NodeJS 代码以 15 fps 创建屏幕截图:

var spawn   = require('child_process').spawn;
var args    = ['-ss', '00:00:07.86', '-i', 'filename.mp4', '-vf', 'fps=15', '/out%d.png'];
var ffmpeg  = spawn('ffmpeg', args);

这很好用,但我想要文件名中每个屏幕截图的时间戳。

来自 FFMPEG 文档:

%t 扩展为时间戳

但是输入... ,'/out%t.png'] 失败并打印:

grep stderr: [image2 @ 0x7f828c802c00] Could not get frame filename 
number 2 from pattern '/Users/***/projects/out%t.png' (either set updatefirst or use a pattern like %03d within the filename pattern)
av_interleaved_write_frame(): Invalid argument
...
grep stderr: Conversion failed!

child process exited with code 1

所以这看起来不像是要走的路。

如何获取每张截图的时间戳?

谢谢

【问题讨论】:

    标签: javascript node.js terminal ffmpeg


    【解决方案1】:

    据我所知,%d 是您在这种情况下可以使用的唯一参数。 使用-report 参数时,您可以使用%t 作为报告文件名,但不能用于视频帧。

    了解视频长度、开始时间 (00:00:07.86) 和 FPS (15),您可以将文件名中的帧号与帧时间戳匹配,并在 ffmpeg 完成提取帧后重命名所有文件。这肯定是一个丑陋的解决方法,但这是我唯一能想到的......

    【讨论】:

      【解决方案2】:

      根据 poohitan 的评论,我最终构建了一个解决方法,将生成的帧数、开始时间和 fps 与实际帧时间戳相关联。

      Video.frameToSec = function(imageName, start, fps) {
      //    imageName => out209.png
          start = start || 0;
      
          var thenum = imageName.match(/\d/g);
          thenum = thenum.join('');
      
          var fps_sec = 1 / fps;
      
          var sec = thenum * fps_sec - fps_sec / 2 + start;
      
          return {imageName:imageName,sec:sec};
      }
      

      可惜 ffmpeg 没有内置属性,因为在创建屏幕截图时时间戳很重要。

      无论如何感谢您的帮助!

      【讨论】:

        猜你喜欢
        • 2019-08-26
        • 2020-12-19
        • 2011-11-18
        • 2012-04-12
        • 2020-03-16
        • 1970-01-01
        • 1970-01-01
        • 2020-01-20
        • 2011-06-12
        相关资源
        最近更新 更多