gpt4 book ai didi

node.js - 带有 node.js 的 FFmpeg。将文件转码为另一种格式

转载 作者:行者123 更新时间:2023-12-04 23:06:31 30 4
gpt4 key购买 nike

对此有点问题,我有一个 .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 等),它都会引发相同的错误

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

最佳答案

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

关于node.js - 带有 node.js 的 FFmpeg。将文件转码为另一种格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24309825/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com