phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.36k stars 1.43k forks source link

Running in Nodejs and accessing each frame #145

Open Janggwan opened 7 years ago

Janggwan commented 7 years ago

Is it possible to run jsmpeg in nodejs and access each frame?

I think the possible ways are: 1) I tried modifying jsmpeg v0.2 to emulate DOM environment through jsdom

it failed with the error 'MaybeClampedUint8Array is not a constructor'. Maybe it seems that window object backed by jsdom doesn't support uint8array.
/home/janggwan/Desktop/Dev/node-rtsp-stream-es6/node_modules/jsmpeg/jsmpg.js:765
        this.currentY = new MaybeClampedUint8Array(this.codedSize);
                        ^

TypeError: MaybeClampedUint8Array is not a constructor
    at module.exports.jsmpeg.initBuffers (/home/janggwan/Desktop/Dev/node-rtsp-stream-es6/node_modules/jsmpeg/jsmpg.js:765:18)

the corresponding code is in jsmpg.js

        // Manually clamp values when writing macroblocks for shitty browsers
        // that don't support Uint8ClampedArray
        var MaybeClampedUint8Array = window.Uint8ClampedArray || window.Uint8Array;
        if (!window.Uint8ClampedArray) {
                this.copyBlockToDestination = this.copyBlockToDestinationClamp;
                this.addBlockToDestination = this.addBlockToDestinationClamp;
        }

        // Allocated buffers and resize the canvas
        this.currentY = new MaybeClampedUint8Array(this.codedSize);
        this.currentY32 = new Uint32Array(this.currentY.buffer);

2) try it using 'node-rtsp-stream-es6' module, and decode mpeg1 stream manually in the client code. (it leveraged jsmpeg v0.2)

https://github.com/Janggwan/node-rtsp-stream-es6

How do I manually decode jsmpeg v0.2 stream?

3) Is there a way to do it with jsmpeg master branch?

It seems that functions for accessing each frame disappeared.

thw0rted commented 6 years ago

Has there been any progress on this? I'm just looking to do some server-side demuxing and thought this sounded promising, but I haven't found any examples of anybody doing this.