forked from john-doherty/raspberry-pi-mjpeg-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcam.js
103 lines (68 loc) · 2.39 KB
/
webcam.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var util = require('util');
module.exports = function Camera(){
this.filename = null;
this.folder = null;
this.parameters= [];
this.takePicture = function takePicture(file,callback){
if (typeof(file) == "function") {
callback = file;
file=null;
}
if(!this.folder){
this.folder = util.format("%s/pitures", __dirname);
}
if(file){
this.filename = util.format("%s/%s", this.folder, file);
}else{
this.filename = util.format("%s/%s.jpg", this.folder, new Date().toJSON());
}
this.output(this.filename);
this.command = "fswebcam";
for (key in this.parameters) {
//JD: remove this as .nopreview required a value in order to be set but the command did not require a value
//if (this.parameters[key]){
this.command+= util.format(' %s %s ', key, this.parameters[key]);
//}
}
var exec = require('child_process').exec,child;
var self = this;
console.log('executing...');
console.log(this.command);
console.log('---');
child = exec(this.command,function (error, stdout, stderr) {
if(callback!==undefined){
callback(self.filename,stderr);
}
});
},
this.quality = function(value){
this.parameters['-jpeg']= value;
return this;
},
this.resolution = function(value){
this.parameters['-r']= value;
return this;
},
this.rotation= function(value){
this.parameters["-rotate"] = value;
return this;
},
this.output= function(value){
this.filename = value;
this.parameters["-save"] = value;
return this;
},
this.verbose= function(value){
this.parameters["-v"] = value;
return this;
},
this.loop= function(value){
this.parameters["-l"] = value;
return this;
},
this.baseFolder = function(directory){
this.folder = directory;
// JD added return this to allow chaining
return this;
}
};