使用nodejs stdoutpipe道输出ffmpeg

我无法通过标准输出pipe道输出ffmpeg。

以下是我编码到目前为止的代码块。

var http = require('http') , fs = require('fs') var child_process = require("child_process") http.createServer(function (req, res) { console.log("Request:", dump_req(req) , "\n") // path of the var path = 'test-mp4.mp4' //test-mp4-long.mp4 , stat = fs.statSync(path) , total = stat.size var range = req.headers.range , parts = range.replace(/bytes=/, "").split("-") , partialstart = parts[0] , partialend = parts[1] , start = parseInt(partialstart, 10) , end = partialend ? parseInt(partialend, 10) : total-1 , chunksize = (end-start)+1 console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize + "\n") var ffmpeg = child_process.spawn("ffmpeg",[ "-i", path, // path "-b:v" , "64k", // bitrate to 64k "-bufsize", "64k", "-" // Output to STDOUT ]); //set header res.writeHead(206 , { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total , 'Accept-Ranges': 'bytes', 'Content-Length': chunksize , 'Content-Type': 'video/mp4' }) stdout[ params[1] ] = ffmpeg.stdout // Pipe the video output to the client response ffmpeg.stdout.pipe(res); console.log("Response", dump_res(res), "\n") }).listen(1337) 

当我从上面的代码replaceffmpeg的东西,一切正常。 以下是代码的一部分,当我更换ffmpeg的东西。

  var file = fs.createReadStream(path, {start: start, end: end}) 

和pipe道一样:

 file.pipe(res) 

我在跑什么毛病?

编辑: ffmpeg命令工作正常。 我已经通过命令行testing了这一点,并生成适当的输出。

你必须通过pipe:1告诉FFmpeg写输出到标准输出。 以下是我的一个项目中的一个例子:

  var ffmpeg = spawn(argv.ffmpeg, [ '-i', argv.file, '-f', 's16le', // PCM 16bits, little-endian '-ar', '44100', // Sampling rate '-ac', 2, // Stereo 'pipe:1' // Output on stdout ]); 

https://github.com/lperrin/node_airtunes/blob/master/examples/play_ffmpeg.js