簡體   English   中英

fluent-ffmpeg縮略圖創建錯誤

[英]fluent-ffmpeg thumbnail creation error

我嘗試用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添加到我的環境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")

請幫我!!!

FFmpeg需要知道視頻文件的持續時間,而大多數視頻在文件頭中有一些文件沒有這些信息,主要是原始視頻,如原始H.264流。

一個簡單的解決方案可能是在拍攝快照之前重新錄制視頻,FFmpeg 0.5命令用於此任務非常簡單:

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

此命令告訴FFmpeg讀取“input.m4v”文件,使用相同的音頻編碼器和視頻編碼器(根本不編碼)輸出,並將數據輸出到文件output.m4v中。

FFmpeg會自動添加稍后拍攝快照所需的所有額外元數據/標頭信息。

嘗試使用此代碼從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/");

我認為這個問題可能是由.withSize('...')方法調用引起的。 醫生說:

它與過濾器沒有很好的相互作用。 特別是,不要使用size()方法來調整縮略圖的大小,而是使用size選項。

size()方法是withSize()的別名。

另外 - 但這不是你的問題 - 你不需要同時設置計數和時間標記。 醫生說:

指定時間戳或時間戳時,將忽略count。

然后你可能會解決:

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

看一下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