【问题标题】:fluent-ffmpeg thumbnail creation errorfluent-ffmpeg 缩略图创建错误
【发布时间】:2012-10-18 09:18:48
【问题描述】:

我尝试使用 fluent-ffmpeg 创建视频缩略图,这是我的代码

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

exports.thumbnail = function(){
    var proc = new ffmpeg({ source: 'Video/express2.mp4',nolog: true })
    .withSize('150x100')
    .takeScreenshots({ count: 1, timemarks: [ '00:00:02.000' ] }, 'Video/', function(err, filenames) {
    console.log(filenames);
    console.log('screenshots were saved');
  });
}

但我不断收到此错误

  "mate data contains no duration, aborting screenshot creation"

知道为什么,

顺便说一句,我在windows上,我把ffmpeg文件夹放在c/ffmpeg中,我把ffmpeg/bin添加到我的环境变量中,我不知道fluent-ffmpeg是否需要知道ffmpeg的路径,但是我可以使用下面的代码成功创建缩略图

   exec("C:/ffmpeg/bin/ffmpeg -i Video/" + Name  + " -ss 00:01:00.00 -r 1 -an -vframes 1 -s 300x200 -f mjpeg Video/" + Name  + ".jpg")

请帮帮我!!!

【问题讨论】:

  • 为了它的价值,我使用 child_process.spawn 直接生成了一个 ffmpeg 进程并且绝对没有问题。将流连接到标准输入、标准输出和标准错误非常简单。

标签: node.js ffmpeg thumbnails


【解决方案1】:

我认为问题可能是由 .withSize('...') 方法调用引起的。 医生说:

它不能很好地与过滤器交互。特别是,不要使用 size() 方法来调整缩略图的大小,而是使用 size 选项。

而size()方法是withSize()的别名。

另外 - 但这不是你的问题 - 你不需要同时设置计数和时间标记。医生说:

指定时间标记或时间戳时忽略计数。

那么你可能可以解决:

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

exports.thumbnail = function(){
    const proc = new ffmpeg({ source: 'Video/express2.mp4',nolog: true })
    .takeScreenshots({ timemarks: [ '00:00:02.000' ], size: '150x100' }, 'Video/', function(err, filenames) {
    console.log(filenames);
    console.log('screenshots were saved');
  });
}

看一下文档: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#screenshotsoptions-dirname-generate-thumbnails

【讨论】:

    【解决方案2】:

    FFmpeg 需要知道视频文件的持续时间,而大多数视频的文件头中都有此信息,有些文件没有,主要是原始视频,如原始 H.264 流。

    一个简单的解决方案是在拍摄快照之前重新混合视频,这个任务的 FFmpeg 0.5 命令非常简单:

    ffmpeg -i input.m4v -acodec copy -vcodec copy output.m4v
    

    此命令告诉FFmpeg读取“input.m4v”文件,使用相同的音频编码器和视频编码器(根本不编码)进行输出,并将数据输出到文件output.m4v中。

    FFmpeg 会自动添加以后拍摄快照所需的所有额外元数据/标头信息。

    【讨论】:

      【解决方案3】:

      尝试使用此代码从视频创建缩略图

      // You have to Install Below packages First
      var ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
      var ffprobePath = require('@ffprobe-installer/ffprobe').path;
      var ffmpeg = require('fluent-ffmpeg');
      ffmpeg.setFfmpegPath(ffmpegPath);
      ffmpeg.setFfprobePath(ffprobePath);
      
      
      
                var proc = ffmpeg(sourceFilePath)
                .on('filenames', function(filenames) {
                  console.log('screenshots are ' + filenames.join(', '));   
                })
                .on('end', function() {
                  console.log('screenshots were saved');
                })
                .on('error', function(err) {
                  console.log('an error happened: ' + err.message);
                })
                // take 1 screenshots at predefined timemarks and size
                .takeScreenshots({ count: 1, timemarks: [ '00:00:01.000' ], size: '200x200' }, "Video/");
      

      【讨论】:

      • 我们应该在我们的环境中用什么替换@ffprobe-installer
      猜你喜欢
      • 2021-06-05
      • 2014-09-07
      • 2011-12-31
      • 2011-04-24
      • 1970-01-01
      • 2013-09-08
      • 2012-07-20
      • 2013-12-20
      • 2015-01-24
      相关资源
      最近更新 更多