Prevent 'after' commands running before 'during' is done
Added helper for Foscam URL's
This commit is contained in:
parent
dd75bef94f
commit
6f1f5f5908
21
capture.js
21
capture.js
@ -87,6 +87,8 @@ module.exports =
|
|||||||
var timer = null;
|
var timer = null;
|
||||||
var req = null;
|
var req = null;
|
||||||
var output = new (require('./output-' + cam.output))(camId, cam.outputOptions, now);
|
var output = new (require('./output-' + cam.output))(camId, cam.outputOptions, now);
|
||||||
|
var duringDone = false;
|
||||||
|
var queueAfter = false;
|
||||||
|
|
||||||
|
|
||||||
runCommands(cam.before, 'before', function()
|
runCommands(cam.before, 'before', function()
|
||||||
@ -105,13 +107,25 @@ module.exports =
|
|||||||
output = null;
|
output = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
runCommands(cam.after, 'after', function() { });
|
// If the stream is cut short, or the time is configured
|
||||||
|
// to be less than the duration of the 'during' commands,
|
||||||
|
// queue it up.
|
||||||
|
if (duringDone)
|
||||||
|
runCommands(cam.after, 'after', function() { });
|
||||||
|
else
|
||||||
|
queueAfter = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
req = http.request(cam.url, function(res)
|
req = http.request(cam.url, function(res)
|
||||||
{
|
{
|
||||||
runCommands(cam.during, 'during', function() { })
|
runCommands(cam.during, 'during', function()
|
||||||
|
{
|
||||||
|
if (queueAfter)
|
||||||
|
runCommands(cam.after, 'after', function() { });
|
||||||
|
else
|
||||||
|
duringDone = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
timer = setTimeout(function()
|
timer = setTimeout(function()
|
||||||
{
|
{
|
||||||
@ -119,6 +133,7 @@ module.exports =
|
|||||||
cleanup();
|
cleanup();
|
||||||
}, cam.time || config.defaultTime || 10000);
|
}, cam.time || config.defaultTime || 10000);
|
||||||
|
|
||||||
|
|
||||||
res.on('end', function()
|
res.on('end', function()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
|
71
config-foscam.js
Normal file
71
config-foscam.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
var url = require('url');
|
||||||
|
var foscam = {};
|
||||||
|
|
||||||
|
// Based on: www.foscam.es/descarga/ipcam_cgi_sdk.pdf
|
||||||
|
// Tested on FI8910W
|
||||||
|
|
||||||
|
function baseUrl(host, cgi, username, password)
|
||||||
|
{
|
||||||
|
var urlObject = {
|
||||||
|
protocol: 'http:',
|
||||||
|
host: host,
|
||||||
|
pathname: cgi,
|
||||||
|
query: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof(username) !== 'undefined')
|
||||||
|
urlObject.query.user = username;
|
||||||
|
|
||||||
|
if (typeof(password) !== 'undefined')
|
||||||
|
urlObject.query.pwd = password;
|
||||||
|
|
||||||
|
return urlObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
rate:
|
||||||
|
image data translate speed, value range 0-23
|
||||||
|
|
||||||
|
0: full speed
|
||||||
|
1: 20 fps
|
||||||
|
3: 15 fps
|
||||||
|
6: 10 fps
|
||||||
|
11: 5 fps
|
||||||
|
12: 4 fps
|
||||||
|
13: 3 fps
|
||||||
|
14: 2 fps
|
||||||
|
15: 1 fps
|
||||||
|
17: 1 fp/2s
|
||||||
|
19: 1 fp/3s
|
||||||
|
21: 1 fp/4s
|
||||||
|
23: 1 fp/5s
|
||||||
|
|
||||||
|
resolution:
|
||||||
|
image resolution (8: 320*240, 32: 640*480)
|
||||||
|
*/
|
||||||
|
foscam.mjpegStream = function(host, username, password, rate, resolution)
|
||||||
|
{
|
||||||
|
var urlObject = baseUrl(host, 'videostream.cgi', username, password);
|
||||||
|
|
||||||
|
if (typeof(resolution) !== 'undefined')
|
||||||
|
urlObject.query.resolution = resolution;
|
||||||
|
|
||||||
|
if (typeof(rate) !== 'undefined')
|
||||||
|
urlObject.query.rate = rate;
|
||||||
|
|
||||||
|
return url.format(urlObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
foscam.gotoPreset = function(host, presetNumber, username, password)
|
||||||
|
{
|
||||||
|
if (presetNumber < 1) presetNumber = 1;
|
||||||
|
if (presetNumber > 32) presetNumber = 32;
|
||||||
|
|
||||||
|
var urlObject = baseUrl(host, 'decoder_control.cgi', username, password);
|
||||||
|
urlObject.query.command = 29 + (presetNumber * 2);
|
||||||
|
|
||||||
|
return url.format(urlObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = foscam;
|
@ -1,3 +1,4 @@
|
|||||||
|
var foscam = require('./config-foscam');
|
||||||
var config = {};
|
var config = {};
|
||||||
|
|
||||||
config.port = 5705;
|
config.port = 5705;
|
||||||
@ -7,7 +8,9 @@ config.cams =
|
|||||||
{
|
{
|
||||||
frontdoor:
|
frontdoor:
|
||||||
{
|
{
|
||||||
url: 'http://10.138.1.10/videostream.cgi?user=viewer&pwd=verysecure',
|
// You can specify any URL string here, the Foscam helper just makes it easier
|
||||||
|
// for compatible models. If you add your own config helper, please publish!
|
||||||
|
url: foscam.mjpegStream('10.138.1.10', 'viewer', 'verysecure'),
|
||||||
time: 5000,
|
time: 5000,
|
||||||
|
|
||||||
output: 'ffmpeg',
|
output: 'ffmpeg',
|
||||||
@ -18,11 +21,17 @@ config.cams =
|
|||||||
videoCodec: 'libx264',
|
videoCodec: 'libx264',
|
||||||
filename: '[/srv/www/publiccam/]YYYY-MM-DD HH.mm.ss[/<camId>.avi]'
|
filename: '[/srv/www/publiccam/]YYYY-MM-DD HH.mm.ss[/<camId>.avi]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO examples for before/after/during commands
|
||||||
},
|
},
|
||||||
|
|
||||||
backdoor:
|
backdoor:
|
||||||
{
|
{
|
||||||
url: 'http://10.138.1.11/videostream.cgi?user=viewer&pwd=verysecure',
|
// You can use username:password@ in the URL to log in with basic
|
||||||
|
// authentication. Note that some cams, like Foscam, use Digest
|
||||||
|
// authentication which is not supported. For Foscam you can provide
|
||||||
|
// the login in the parameters instead.
|
||||||
|
url: 'http://viewer:verysecure@10.138.1.11/video.cgi',
|
||||||
time: 5000,
|
time: 5000,
|
||||||
|
|
||||||
output: 'mjpeg-split',
|
output: 'mjpeg-split',
|
||||||
|
Loading…
Reference in New Issue
Block a user