简体   繁体   中英

fluent-ffmpeg thumbnail creation error

i try to create a video thumbnail with fluent-ffmpeg here is my code

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

   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.

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 -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 automatically adds all extra metadata/header information needed to take the snapshot later.

Try this code to create thumbnails from 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. 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.

And the size() method is an alias of 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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