I am trying to read in large volumes of binary data from a stream (created form a child process) in Node. I am using the stdout.on('data') event for my process to get the data.
No matter how much I search, I can't seem to find any docs on the arguments that are passed in to the callback. typeof(data) says it's an object, but from what I can tell, it is just an array.
Is it an array? Or a string? Whatever it is, how can I get an array of bytes out?
Here's my code:
var childProc = require('child_process'),
spawn = childProc.spawn;
// /home/ubuntu/bin/ffmpeg -f video4linux2 -r 1 -s 640x480 -i /dev/video0 -c:v rawvideo -f rawvideo -pix_fmt rgb8 -
var streamProc = spawn('/home/ubuntu/bin/ffmpeg', [
'-f', 'video4linux2',
'-r', '1',
'-s', '640x480',
'-i', '/dev/video0',
'-c:v', 'rawvideo',
'-f', 'rawvideo',
'-pix_fmt', 'rgb24',
'-'
]);
streamProc.stdout.on('data', function(data) {
var bytes = [];
//Do some magical conversion here to populate the array
//debugger;
console.log('OUT: ' + bytes.join()); //Just some debugging steps
});
streamProc.stderr.on('data', function(data) {
//debugger;
if(process.argv.indexOf('showerr') != -1)
console.log('ERR: ' + data);
});
streamProc.on('close',function(exitCode) {
console.log('EXT: Program exited with code ' + exitCode);
});
Am I missing something obvious?