0

对此有点问题,我有一个 .avi 文件,我想在其中使用 FFmpeg 将其转码为 .flv 文件,这是我目前所拥有的:

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

//make sure you set the correct path to your video file
var proc = new ffmpeg({ source: 'C:/Users/Jay/Documents/movie/drop.avi', nolog: true })

//Set the path to where FFmpeg is installed
.setFfmpegPath("C:\Users\Jay\Documents\FFMPEG")

//set the size
.withSize('50%')

// set fps
.withFps(24)

// set output format to force
.toFormat('flv')

// setup event handlers
.on('end', function() {
    console.log('file has been converted successfully');
})
.on('error', function(err) {
    console.log('an error happened: ' + err.message);
})
// save to file <-- the new file I want -->
.saveToFile('C:/Users/Jay/Documents/movie/drop.flv');

它看起来很简单,我可以通过 FFmpeg 命令行来完成,但我试图让它在 node.js 应用程序中工作,这是它返回的错误:

C:\Users\Jay\workspace\FFMPEGtest\test.js:17
.withSize('50%')
 ^
TypeError: Cannot call method 'withSize' of undefined
    at Object.<anonymous> (C:\Users\Jay\workspace\FFMPEGtest\test.js:17:2)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

对于每个内置的 FFmpeg 函数(.toFormat、.withFPS 等),它都会引发相同的错误

如果有人对此有解决方案,我将不胜感激

4

1 回答 1

3

setFfmpegPath()不返回 的实例this,如源代码中所示 这意味着您不能链接该方法。

将其更改为

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

//make sure you set the correct path to your video file
var proc = new ffmpeg({ source: 'C:/Users/Jay/Documents/movie/drop.avi', nolog: true })

//Set the path to where FFmpeg is installed
proc.setFfmpegPath("C:\\Users\\Jay\\Documents\\FFMPEG")

proc
//set the size
.withSize('50%')

// set fps
.withFps(24)

// set output format to force
.toFormat('flv')

// setup event handlers
.on('end', function() {
    console.log('file has been converted successfully');
})
.on('error', function(err) {
    console.log('an error happened: ' + err.message);
})
// save to file <-- the new file I want -->
.saveToFile('C:/Users/Jay/Documents/movie/drop.flv');
于 2014-06-19T15:11:38.317 回答