Coder Social home page Coder Social logo

node-mjpeg-server's Introduction

mjpeg-server

Serve an mjpeg stream on a specified port through HTTP from multiple jpgs.

Methods

mjpegServer.createReqHandler(req, res)

Creates a request handler object with parameters from http.createServer.

var http = require('http');
var mjpegServer = require('..');

http.createServer(function(req, res) {
	mjpegReqHandler = mjpegServer.createReqHandler(req, res);
}).listen(8081);

mjpegServer.update(data)

Update the stream

mjpegReqHandler = mjpegServer.createReqHandler(req, res);
mjpegReqHandler.update(randomJpeg37);

mjpegServer.close()

Calls res.end

Changelog

0.3.1

  • Fixed a deprecation warning in Node.js 16.x due to a typo in the package.json main field.

0.3

  • Use streams2 in Node.js v.10

node-mjpeg-server's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-mjpeg-server's Issues

DeprecationWarning node v16.4.0

When I launch appium I am getting this message.

(node:6668) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/......./.nvm/versions/node/v16.4.0/lib/node_modules/appium/node_modules/mjpeg-server/package.json' of './lib/mpegserver'. Please either fix that or report it to the module author
(Use node --trace-deprecation ... to show where the warning was created)

I then ran ..... this is the package with in appium

node --trace-deprecation /Users/stephen.lichtenberg/.nvm/versions/node/v16.4.0/lib/node_modules/appium/node_modules/mjpeg-server
(node:6772) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/......./.nvm/versions/node/v16.4.0/lib/node_modules/appium/node_modules/mjpeg-server/package.json' of './lib/mpegserver'. Please either fix that or report it to the module author
at tryPackage (node:internal/modules/cjs/loader:358:15)
at Function.Module._findPath (node:internal/modules/cjs/loader:560:18)
at resolveMainPath (node:internal/modules/run_main:15:25)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:73:24)
at node:internal/main/run_main_module:17:47

I then installed the package outside of the appium packages.

node --trace-deprecation /Users/........./.nvm/versions/node/v16.4.0/lib/node_modules/mjpeg-server
(node:6903) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/stephen.lichtenberg/.nvm/versions/node/v16.4.0/lib/node_modules/mjpeg-server/package.json' of './lib/mpegserver'. Please either fix that or report it to the module author
at tryPackage (node:internal/modules/cjs/loader:358:15)
at Function.Module._findPath (node:internal/modules/cjs/loader:560:18)
at resolveMainPath (node:internal/modules/run_main:15:25)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:73:24)
at node:internal/main/run_main_module:17:47

Output appears cropped in VLC?

Hi,

Thanks for the library, its been really useful to quickly create a mjpg stream. There is one odd thing though. If I open the output stream in vlc, the video is zoomed and cropped. If you do it the example you'll see that the numbers appear much nearer the bottom right corner than if you open the stream in a browser. I investigated if it was a setting in VLC but I don't think it is? Does the stream have to specifiy dimensions or something that might be getting set properly?

Any ideas?

Thanks

Is this missing a close handler?

Hi, I would like to send an mjpeg stream based on this module, working like this:

  • at server start, begin fetching images from camera, make eventEmitter for "new image"
  • when client connects to /live, create mjpeg stream, and subscribe to "new image" notifications
  • when the client disconnects, unsubscribe and release objects for garbage collection

Very simple, however, I wonder what happens when the client disconnects? I don't see an on('close') handler on the response? I suppose the mjpegServer could take an extra callback for when the client quits?

mjpegReqHandler.write

it seems like the mjpegReqHandler.write method only works when I clone the module straight from github rather than npm install it...is that correct?
sorry just curious, if the case i don't include this in my package.json but make a note to install manually

API improvements?

I know this implements a Writable, but I was mistakenly using it as fs.createReadStream("img.jpg").pipe(mjpegStream, {end: false}), which doesn't work, since it needs to send the full size of the file in _write.

So now I wonder if one can send an image without specifying size? Or does the mjpeg stream require sizes?

If so, it may be better to expose .sendFile(path) and .sendBuffer(buffer) and keep the Writable hidden. Here's my .sendFile:

MjpegServer.prototype.sendFile = function(path, cb) {
	const onRead = (err, data) => {
		if (err) {return cb && cb(err)}
		this.write(data)
		cb && cb()
	}
	try {
		fs.readFile(path, onRead)
	} catch(err) {
		cb && cb(err)
	}
};

Maybe this can be improved, for example by checking if the previous frame was already sent through res, and if not, skip the frame? Not sure if that is even possible.

Stream from memory rather than file

Hello,

I just cam across this repository and it seems almost perfect. Would it be possible to modify the code to be used with in-memory image rather than a file?

I need to acquire an image from the raspberry camera, make some changes (ad overlay text, etc) and stream to a web browser. With reference to the example you provided.

Everything works fine if I do: 1) acquire, 2) save to file, 3) read, 4) call sendJPGData. However I would like to avoid disk access and use the data in memory: 1) acquire, 2) call sendJPGData

In his case I got the following error:

_stream_writable.js:269
var len = state.objectMode ? 1 : chunk.length;
^
TypeError: Cannot read property 'length' of undefined
at writeOrBuffer (_stream_writable.js:269:41)
at MjpegServer.Writable.write (_stream_writable.js:217:11)
at sendJPGData (/home/pi/node-mjpeg-server/examples/server.js:56:21)
at /home/pi/node-mjpeg-server/examples/server.js:42:2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.