NodeJS:为模块Fluent-FFMPEG设置FFMPEG二进制文件的路径

jan*_*s86 3 ffmpeg path binaries node.js

我正在构建一个使用模块node-fluent-ffmpeg的应用程序.https://github.com/schaermu/node-fluent-ffmpeg

我正在尝试将ffmpeg二进制文件与我的应用程序一起打包.我想这样做(特别是在Windows上),用户不必手动安装FFMPEG.

可悲的是,我尝试的一切都会导致错误.我尝试过以下方法:

  ffmpeg.setFfmpegPath   : Gives an error saying setFfmpegPath is not a method
Run Code Online (Sandbox Code Playgroud)

和:

  proc.setFfmpegPath    : Gives a createproces error.
Run Code Online (Sandbox Code Playgroud)

看来我做错了什么.有人可以指出我的错误.非常感谢.

jan*_*s86 5

我修理它!我不知道我必须在路径中包含二进制文件.所以我做了这样的事情:

  if(os.platform() === 'win32'){
     var ffmpegPath = './bin/ffmpeg/ffmpeg.exe'
 }else{
     var ffmpegPath = './bin/ffmpeg/ffmpeg'
 }

 proc = new ffmpeg({ source: movieUrl, nolog: true, timeout: FFMPEG_TIMEOUT })
 proc.setFfmpegPath(ffmpegPath)
 proc.addOptions(opts)
 proc.writeToStream(response, function(return_code, error){
Run Code Online (Sandbox Code Playgroud)

  • 一,也可以使用可以跨平台工作的 shelljs 模块。`var shell = require('shelljs');``var ffmpegPath = shell.which('ffmpeg');` (2认同)