我想要做的是使用ffmpeg製作視頻的縮略圖。視頻數據通過HTTP請求接收,然後通過管道傳輸到ffmpeg。問題是,一旦ffmpeg子進程退出,我根本無法發回響應。FFMPEG掛起整個nodejs進程
下面是代碼:
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");
的問題是,美其名曰:
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('{"success":true}\n');
什麼都不做,客戶端永遠不會收到響應。
我不熟悉node.js,但我無法想象你需要創建寫入原始json作爲字符串發送json回到用戶... – ThiefMaster