2017-02-18 80 views
0

我在下面的代碼嘗試。誰能告訴我什麼是錯的代碼轉換視頻爲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

回答

0

你有沒有文件或目錄的錯誤。在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'); 
+0

它的工作

嘗試! 謝謝。 –