
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
mjpeg-decoder
Advanced tools
A NodeJS M-JPEG decoder which can be used to retrieve individual JPEG frames or take a snapshot from a IP/network camera which serves M-JPEG video stream.
A NodeJS M-JPEG decoder which can be used to retrieve individual JPEG frames or take a snapshot from a IP/network camera which serves M-JPEG video stream.
npm install mjpeg-decoder
or
yarn add mjpeg-decoder
Typically, you use the mjpeg-decoder to read JPEG frames from an M-JPEG video stream.
const fs = require('fs');
const MjpegDecoder = require('mjpeg-decoder');
// create a decoder which delivers a JPEG frame
// via the 'frame' event every 3 seconds.
const decoder = new MjpegDecoder(
'<your stream url>', { interval: 3000 }
);
decoder.on('frame', (frame, seq) => {
fs.writeFileSync(`${seq}.jpg`, frame);
});
decoder.start();
But sometimes, you just want to take a snapshot of the M-JPEG video stream, and then forget. In this case, you can do like this:
// create a decoder which takes a snapshot and forget
const decoder = new MjpegDecoder(
'<your stream url>', { maxFrames: 1 }
);
const frame = await decoder.takeSnapshot();
fs.writeFileSync('snapshot.jpg', frame);
Or, you can use the MjpegDecoder.decoderForSnapshot shorthand method to create the decoder instance:
const decoder = MjpegDecoder.decoderForSnapshot('<your stream url>');
const frame = await decoder.takeSnapshot();
fs.writeFileSync('snapshot.jpg', frame);
MjpegDecoder.MjpegDecoderOptions
interval: Specify the time interval in which the frames will be delivered (default: 0)maxFrames: Specify the max frames to consume before stopping (default: 0)timeout: Specify the timeout before the http connection is aborted (default: 10000ms)constructor(url: string, options?: Partial<MjpegDecoder.MjpegDecoderOptions>)
url: url of the M-JPEG video stream source.options: control how the decoder will work as expected.How to find the url of the camera? The camera user manual should usually mention the URL, or searching the camera model number should get you a result as well. You can also try this tool http://skjm.com/icam/mjpeg.php or this tool https://www.ispyconnect.com/man.aspx.
static decoderForSnapshot(
url: string,
options?: Partial<MjpegDecoder.MjpegDecoderOptions>
): MjpegDecoder
Create an instance of MjpegDecoder used to take a onetime snapshot of the video stream.
url: url of the M-JPEG video stream source.options: control how the decoder will work as expected.start(): void
Start the M-JPEG decoder and begin consuming the M-JPEG video stream. Listen for 'frame' event to get the decoded JPEG frames sequently.
stop(): void
Stop consuming the M-JPEG video stream.
takeSnapshot(): Promise<Buffer>
Take snapshot of the M-JPEG video stream.
on(event: 'frame', listener: (frame: Buffer, seq: number) => void): this
Add listener for frame event which is emitted when a JPEG frame is decoded. The event listener takes the decoded JPEG frame and sequence number as the parameters.
on(event: 'abort', listener: (reason: MjpegDecoder.AbortReason, error?: Error) => void): this
Add listener for abort event which is emitted for some reason. The decoder will stop consuming the video stream in the following cases:
timeout: network timeout while connecting to the video stream source at the given url.http_error: when a network error or http error occuredinvalid_mjpeg_stream: if the source is not a valid M-JPEG video streamend: when you call the stop method of the decoder or the max frames have been delivered.max_buffer_size_exceeded: when the internal data buffer size reached the limit, and this might be caused by the M-JPEG decoding problem. If you accountered this error, please create an issue.Use wget:
$ wget <url> -O snapshot.jpg
Use ffmpeg:
ffmpeg -f MJPEG -y -i <url> -r 1 -vframes 1 -q:v 1 snapshot.jpg
FAQs
A NodeJS M-JPEG decoder which can be used to retrieve individual JPEG frames or take a snapshot from a IP/network camera which serves M-JPEG video stream.
The npm package mjpeg-decoder receives a total of 22 weekly downloads. As such, mjpeg-decoder popularity was classified as not popular.
We found that mjpeg-decoder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.