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

标签 node.js ffmpeg transcode

对此有点问题,我有一个 .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/

相关文章:

node.js - 快速 JS 安装

linux - 使用 mencoder 或 ffmpeg 时特殊字符变得不明确

ffmpeg - 如何更正 ffmpeg 以流式传输我的 mp4?

linux - 移动新创建的文件

video - 播放两个视频,如何在 FFmpeg 中裁剪第二个视频

node.js - 后端 API 服务器 Typescript/Webpack 版本 : Module not found: Error: Can't resolve

node.js - 无法让express.js与IISNode一起工作

ffmpeg - ffprobe 或 avprobe 在 JSON 输出中返回纯文本错误

java - 如何使用 FFMPEG 对文件进行转码并在 Java servlet 的响应中流式传输输出文件?

node.js - 拒绝将 'module' 安装为自身的依赖项