-
Notifications
You must be signed in to change notification settings - Fork 858
/
write-video.js
59 lines (48 loc) · 1.16 KB
/
write-video.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var cv = require('../lib/opencv');
var path = require('path');
var vid = new cv.VideoCapture(path.join(__dirname, 'files', 'motion.mov'));
vid.read(function(err, mat) {
if (err) throw err;
var filename = './output-'+new Date().getTime()+'.avi';
var writer = new cv.VideoWriter(filename, 'DIVX', vid.getFPS(), mat.size(), true);
writer.writeSync(mat);
var x = 0;
var iter = function () {
vid.read(function (err, m2) {
x++;
writer.writeSync(m2);
if (x < 100) {
iter();
} else {
vid.release();
writer.release();
}
})
};
iter();
});
// restart video read
var vid2 = new cv.VideoCapture(path.join(__dirname, 'files', 'motion.mov'));
var filename2 = './output-async-'+new Date().getTime()+'.avi';
var writer2 = null;
var x = 0;
// do the same write async
var iter = function () {
vid2.read(function (err, m2) {
if (writer2 === null)
writer2 = new cv.VideoWriter(filename2, 'DIVX', vid2.getFPS(), m2.size(), true);
x++;
writer2.write(m2, function(err){
if (x < 100) {
iter();
} else {
vid2.release();
writer2.release();
}
});
m2.release();
delete m2;
});
};
// kick it off
iter();