简体   繁体   English

fluent-ffmpeg缩略图创建错误

[英]fluent-ffmpeg thumbnail creation error

i try to create a video thumbnail with fluent-ffmpeg here is my code 我尝试用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');
  });
}

but i keep getting this error 但我一直收到这个错误

  "mate data contains no duration, aborting screenshot creation"

any idea why, 任何想法为什么,

by the way am on windows, and i put the ffmpeg folder in c/ffmpeg ,and i added the ffmpeg/bin in to my environment varable, i dont know if fluent-ffmpeg need to know the path of ffmpeg,but i can successfully create a thumbnail with the code below 顺便说一句,在Windows上,我将ffmpeg文件夹放在c / ffmpeg中,我将ffmpeg / bin添加到我的环境varable中,我不知道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")

please help me!!! 请帮我!!!

FFmpeg needs to know the duration of a video file, while most videos have this information in the file header some file don't, mostly raw videos like a raw H.264 stream. FFmpeg需要知道视频文件的持续时间,而大多数视频在文件头中有一些文件没有这些信息,主要是原始视频,如原始H.264流。

A simple solution could be to remux the video prior to take the snapshot, the FFmpeg 0.5 command for this task it's quite simple: 一个简单的解决方案可能是在拍摄快照之前重新录制视频,FFmpeg 0.5命令用于此任务非常简单:

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

This command tells FFmpeg to read the "input.m4v" file, to use the same audio encoder and video encoder (no encoding at all) for the output, and to output the data into the file output.m4v. 此命令告诉FFmpeg读取“input.m4v”文件,使用相同的音频编码器和视频编码器(根本不编码)输出,并将数据输出到文件output.m4v中。

FFmpeg automatically adds all extra metadata/header information needed to take the snapshot later. FFmpeg会自动添加稍后拍摄快照所需的所有额外元数据/标头信息。

Try this code to create thumbnails from Video 尝试使用此代码从Video创建缩略图

// 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/");

I think the issue can be caused by the .withSize('...') method call. 我认为这个问题可能是由.withSize('...')方法调用引起的。 The doc says: 医生说:

It doesn't interract well with filters. 它与过滤器没有很好的相互作用。 In particular, don't use the size() method to resize thumbnails, use the size option instead. 特别是,不要使用size()方法来调整缩略图的大小,而是使用size选项。

And the size() method is an alias of withSize(). size()方法是withSize()的别名。

Also - but this is not the problem in your case - you don't need to set either the count and the timemarks at the same time. 另外 - 但这不是你的问题 - 你不需要同时设置计数和时间标记。 The doc says: 医生说:

count is ignored when timemarks or timestamps is specified. 指定时间戳或时间戳时,将忽略count。

Then you probably could solve with: 然后你可能会解决:

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');
  });
}

Have a look at the doc: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#screenshotsoptions-dirname-generate-thumbnails 看一下doc: https//github.com/fluent-ffmpeg/node-fluent-ffmpeg#screenshotsoptions-dirname-generate-thumbnails

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM