有一点问题,我有一个.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等)
如果有人有解决方案,我会非常感激
答案 0 :(得分:2)
setFfmpegPath()
不会返回this
的实例,如源here.中所示
意思是你不能链接方法。
将其更改为
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');