我想要做的是使用ffmpeg制作视频的缩略图.视频数据在HTTP请求中接收,然后通过管道传输到ffmpeg.问题是,一旦ffmpeg子进程退出,我就无法发回响应.
这是代码:
var http = require('http'),
sys = require('sys'),
child = require('child_process')
http.createServer(function (req, res) {
im = child.spawn('ffmpeg',['-i','-','-vcodec','mjpeg','-ss','00:00:03','-vframes','1','-s','100x80','./thumb/thumbnail.jpg']);
im.on('exit', function (code, signal) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}\n');
});
req.connection.pipe(im.stdin);
}).listen(5678, "127.0.0.1");
Run Code Online (Sandbox Code Playgroud)
问题是调用:
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}\n');
Run Code Online (Sandbox Code Playgroud)
什么都不做,客户端永远不会收到回复.