转换视频为mp3 node.js
问题描述:
我在下面的代码尝试。谁能告诉我什么是错的代码转换视频为mp3 node.js
var ffmpeg = require('fluent-ffmpeg');
var proc = new ffmpeg({ source: 'C:/Users/Public/Videos/Sample
Videos/Wildlife.wmv', nolog: true })
proc.setFfmpegPath("C:\\nodejs\\ffmpeg")
.toFormat('mp3')
.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/Public/Videos/Sample Videos/Wildlife.mp3');
C:\的NodeJS>节点test.js 错误发生了:产卵C:\的NodeJS \ ffmpeg的ENOENT
答
你有没有文件或目录的错误。在Windows平台上,它需要绝对路径下面的代码
var os = require('os'); // add at top
var ffmpeg = require('fluent-ffmpeg');
var proc = new ffmpeg({ source: 'C:/Users/Public/Videos/Sample
Videos/Wildlife.wmv', nolog: true })
if(os.platform() === 'win32'){
proc.setFfmpegPath("C:\\nodejs\\ffmpeg.exe")
}else{
proc.setFfmpegPath("C:\\nodejs\\ffmpeg") // change it for linux
}
.toFormat('mp3')
.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/Public/Videos/Sample Videos/Wildlife.mp3');
它的工作
尝试! 谢谢。 –