mmaelzer / motion Goto Github PK
View Code? Open in Web Editor NEWA node.js motion detection library that supports node.js streams.
A node.js motion detection library that supports node.js streams.
Let me prefix all of the following by saying this isn't my area, so I may be completely on the wrong track. I think, however, there's something that doesn't make sense about your example in the README.md for this module.
The key hinges on this line:
request(options).pipe(consumer).pipe(motion).pipe(writer);
In other words, MjpegConsumer
is being fed directly into motion-detect
(which in turns uses motion
). However, I just couldn't get this working. After bashing my head against it, and creating a poor-man's stream to replace motion-detect
and talk directly to motion.js
, I think I understand. What MjpegConsumer
generates is JPEG files. However, these are (by the lossy nature of JPEGs) variable in length. What motion appears to be expecting (which might explain the line I referred to in issue #6) is RGBA arrays. So I've knocked together some code that uses https://www.npmjs.com/package/jpeg-js
to decode the JPGs into RGBA arrays, and bingo - now motion works!
What I don't get is how your example ever worked? Did you miss something from the sample code? Am I still fundamentally missing something?
FWIW, my code looks approx like this:
var jpeg = require('jpeg-js');
class FrameHandler extends Stream {
constructor () {
super()
this.motion = new Motion()
this.lastFrame = []
}
write (newFrame) {
const newFrameRGBA = jpeg.decode(newFrame).data
let hasMotion = this.motion.detect(newFrameRGBA, this.lastFrame)
let diff = this.motion.diff(newFrameRGBA, this.lastFrame)
this.lastFrame = newFrameRGBA
if (hasMotion) { logger.debug('Motion detected') }
}
}
var consumer = new MjpegConsumer()
request(options).pipe(consumer).pipe(new FrameHandler())
Hi there,
Sorry to bother you - but I'd like to stream the output of getBlendedImage(image1, image2) over a websocket to a client - however, I cannot seem to work out how to convert the RGBA array into a base64 encoded data uri (so that it can be directly loaded in as a src in an img).
Any pointers you could give would be greatly appreciated...
Hi, it appears there is an inconsistency between the version of motion-detect on GitHub and the version on npm.
I've traced it to the stray line if(img1.length !== img2.length) return null;
in lib/motion.js
(which is I assume should not be present and is a bug. The version of motion.js
(which corresponds to a package.json
of 0.2.4) on GitHub does not have this line, but the version downloaded via npm install
does.
Thanks for your work on this great library.
Hello, is there any example of videostream.cgi for this repo?
I don't know how to create it, thanks.
Firstly, thank you very much for putting this together, I've been experimenting with it for the past couple days, and it has really surpassed my expectations. I really appreciate the time you've put into it, and I would love to help with anything moving forward.
I am testing out the Usage example (under "Motion Stream") where we write images to a file:
request(options).pipe(consumer).pipe(motion).pipe(writer);
I have found that I am sometimes getting JPEGs that are invalid. I'm not quite sure where in the process something goes wrong, but upon converting the JPEGs into a GIF using this command:
convert -delay 3 -loop 0 video/*.jpg monday.gif
Several of the file conversion produces errors that look like this:
convert: Not a JPEG file: starts with 0x34 0x38 video/1457373787249.jpg' @ error/jpeg.c/JPEGErrorHandler/322.
convert: Not a JPEG file: starts with 0x5f 0x30 video/1457373788733.jpg' @ error/jpeg.c/JPEGErrorHandler/322.
convert: Not a JPEG file: starts with 0x36 0x0d video/1457373789767.jpg' @ error/jpeg.c/JPEGErrorHandler/322.
convert: Not a JPEG file: starts with 0x3a 0x30 video/1457373792936.jpg' @ error/jpeg.c/JPEGErrorHandler/322.
I don't mind digging around to investigate this issue, but I was wondering if you knew what could be happening? Or possibly what part of the process could lead to resulting in corrupted jpeg images?
Thank you very much again,
Doug
I wanna do some event when motion has been detected, what should I do?
Nothing happening
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.