Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added motion emitting and MJPEG saving
- Loading branch information
1 parent
49c5b73
commit 768f714
Showing
9 changed files
with
241 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* MJPEG decoder for Axis cameras | ||
* Breaks the MJPEG stream into invidividual JPEG images | ||
*/ | ||
|
||
var Transform = require('stream').Transform | ||
|
||
Buffer.prototype.toByteArray = function () { | ||
return Array.prototype.slice.call(this, 0) | ||
} | ||
|
||
var MJPGStream = function() { | ||
Transform.call(this, {objectMode: true}) | ||
} | ||
|
||
MJPGStream.prototype = Object.create( | ||
Transform.prototype, { constructor: { value: MJPGStream }}) | ||
|
||
MJPGStream.prototype._transform = function(data, encoding, cb) { | ||
// Step through the data, looking for start/end markers (SOI/EOI) | ||
for (var i = 0; i < data.length - 1; i++) { | ||
var num = data.readUInt16BE(i) | ||
if (num === 0xffd8) { | ||
this.imgBuff = [] | ||
} | ||
else if (num === 0xffd9) { | ||
this.push(new Buffer(this.imgBuff.concat([0xff, 0xd9]))) | ||
this.imgBuff = null | ||
} | ||
if (this.imgBuff) | ||
this.imgBuff.push(data[i]) | ||
} | ||
cb() | ||
} | ||
|
||
exports.createStream = function() { | ||
return new MJPGStream() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Parses out motion data from the Axis camera motion stream | ||
* Implemented with the new Node streams using prototypes | ||
*/ | ||
var Transform = require('stream').Transform | ||
|
||
var MotionLevelStream = function() { | ||
Transform.call(this, {objectMode: true}) | ||
} | ||
|
||
MotionLevelStream.prototype = Object.create( | ||
Transform.prototype, { constructor: { value: MotionLevelStream }}) | ||
|
||
MotionLevelStream.prototype._transform = function(data, encoding, cb) { | ||
var that = this | ||
// Important bit of the stream is: group=0;level=0;threshold=11; | ||
var match = data.toString().match(/group=\d+;level=\d+;threshold=\d+/g) | ||
if (match) | ||
match.forEach(function(motion) { | ||
var motionMatch = motion.match(/group=(\d+);level=(\d+);threshold=(\d+)/) | ||
that.push({ group: Number(motionMatch[1]), | ||
level: Number(motionMatch[2]), | ||
threshold: Number(motionMatch[3]), | ||
ts: new Date }) | ||
}) | ||
cb() | ||
} | ||
|
||
exports.createStream = function() { | ||
return new MotionLevelStream() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Parses out motion data from the Axis camera motion stream | ||
* Implemented with the new Node streams | ||
*/ | ||
var stream = require('stream'), | ||
util = require('util') | ||
|
||
var MotionLevelStream = function() { | ||
stream.Transform.call(this, {objectMode: true}) | ||
|
||
this._transform = function(data, encoding, cb) { | ||
var that = this | ||
// Important bit of the stream is: group=0;level=0;threshold=11; | ||
var match = data.toString().match(/group=\d+;level=\d+;threshold=\d+/g) | ||
if (match) | ||
match.forEach(function(motion) { | ||
var motionMatch = motion.match(/group=(\d+);level=(\d+);threshold=(\d+)/) | ||
that.push({ group: Number(motionMatch[1]), | ||
level: Number(motionMatch[2]), | ||
threshold: Number(motionMatch[3]), | ||
ts: new Date }) | ||
}) | ||
cb() | ||
} | ||
|
||
} | ||
|
||
util.inherits(MotionLevelStream, stream.Transform) | ||
|
||
exports.createStream = function() { | ||
return new MotionLevelStream() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters