Skip to content

Instantly share code, notes, and snippets.

@kanryu
Created December 21, 2012 07:45
Show Gist options
  • Select an option

  • Save kanryu/4351283 to your computer and use it in GitHub Desktop.

Select an option

Save kanryu/4351283 to your computer and use it in GitHub Desktop.

Revisions

  1. kanryu created this gist Dec 21, 2012.
    37 changes: 37 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    //// problem: node.js make memory leaks about child_proces
    //
    // the javascript doing it tha same to the shell code
    // $ cat mako_* | ./ffmpeg -y -f image2pipe -r 1 -vcodec bmp -r 29.7 -i - -vcodec utvideo movie.avi


    var ffmpeg = require('basicFFmpeg');
    var fs = require('fs');
    var sprintf = require('sprintf').sprintf;
    var spawn = require('child_process').spawn,
    exec = require('child_process').exec;


    function genProcArgs(processor) {
    var args = ['-y', '-f', 'image2pipe', '-r', '1', '-vcodec', 'bmp', '-r', '29.7', '-i', '-', '-vcodec', 'utvideo', '-f', 'avi'];
    // args.push('pipe:1');
    args.push("test.avi");
    return args;
    }

    var proc = spawn('ffmpeg', genProcArgs());

    for(var j = 0; j < 1000; j++) {
    for(var i = 0; i <= 12; i++) {
    var path = sprintf("mako_%04d.bmp", i);
    var data = fs.readFileSync(path);
    console.log(j, i);

    // 1. writing out to ffmpeg process, occars memory leaks
    proc.stdin.write(data);

    //// 2. writing out to a local file, no memory leaks
    // fs.appendFileSync("m.bmp", data);
    }
    }
    proc.stdin.end();