Skip to content

Instantly share code, notes, and snippets.

@kanryu
Created December 21, 2012 07:45
Show Gist options
  • Save kanryu/4351283 to your computer and use it in GitHub Desktop.
Save kanryu/4351283 to your computer and use it in GitHub Desktop.
problem: node.js make memory leaks about child_proces
//// 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment