forked from binarykitchen/avconv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avconv.js
37 lines (28 loc) · 933 Bytes
/
avconv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = avconv;
var spawn = require('child_process').spawn;
function avconv(params, callback) {
var stdout = ''
, stderr = ''
, avconv = spawn('avconv', params);
// avconv output is always written into stderr
if (avconv.stderr)
avconv.stderr.on('data', function(data) {
// write it into stdout instead
stdout += data;
});
// just in case if there is something interesting
if (avconv.stdout)
avconv.stdout.on('data', function(data) {
stdout += data;
});
avconv.on('error', function(data) {
if (data.length)
data += ' ';
stderr += data;
});
// new stdio api introduced the exit event not waiting for open pipes
var eventType = avconv.stdio ? 'close' : 'exit';
avconv.on(eventType, function(code) {
callback(code, stdout, stderr);
});
}