我想将 youtube 网址转换为 mp3 文件。目前,我使用节点的 ytdl 模块下载 mp4,如下所示:
fs = require 'fs'
ytdl = require 'ytdl'
url = 'http://www.youtube.com/watch?v=v8bOTvg-iaU'
mp4 = './video.mp4'
ytdl(url).pipe(fs.createWriteStream(mp4))
下载完成后,我使用 fluent-ffmpeg 模块将 mp4 转换为 mp3,如下所示:
ffmpeg = require 'fluent-ffmpeg'
mp4 = './video.mp4'
mp3 = './audio.mp3'
proc = new ffmpeg({source:mp4})
proc.setFfmpegPath('/Applications/ffmpeg')
proc.saveToFile(mp3, (stdout, stderr)->
return console.log stderr if err?
return console.log 'done'
)
我不想在开始 mp3 转换之前保存整个 mp4。如何将 mp4 通过管道传输到 proc 中,以便它在接收 mp4 块时执行转换?