child_process标准输出完成事件

时间:2014-05-15 11:56:11

标签: node.js

我正在使用以下代码对视频进行转码

var input_file = fs.createReadStream(req.files.file.path);
var output_file = fs.createWriteStream(filePathh);

var args = ['-i', 'pipe:0', '-f', 'mp4', '-strict', 'experimental', '-movflags', 'frag_keyframe', 'pipe:1'];
var trans_proc = child.spawn('avconv', args, null);

input_file.pipe(trans_proc.stdin);
trans_proc.stdout.pipe(output_file);

trans_proc.stderr.on('end', function (data) {
    // console.log(data.toString());

    var fileid = new ObjectID();

    var gridStoreWrite = new GridStore(db, fileid, req.files.file.name, "w", {});

    gridStoreWrite.writeFile(filePathh, function (err, result) {
        if (err) {
            //console.log("Write Error");
            //fileId_ = null;
            res.send(err);
            // cb(null, true);
        } else {
            //console.dir(result);
            // fileId_ = fileid;
            console.log(fileid);
            res.send(fileid);
            // cb(null, true);
        }
    });
});

但这是多次向GridFS写入文件。如何在转换完成时修复它以写入GridFS。

0 个答案:

没有答案