Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remuxing into MP4 #3

Open
TroyKomodo opened this issue Dec 20, 2020 · 1 comment
Open

Remuxing into MP4 #3

TroyKomodo opened this issue Dec 20, 2020 · 1 comment

Comments

@TroyKomodo
Copy link

Hi, i was curious how i would approach the remux into mp4?

Currently i am reading the data via WebSocket and is being sent over mpegts and I want to add this into a HTMLMediaElement via the SourceBuffer API but i need to demux and then remux in to mp4 to allow for this, as far as i know.

@neodescis
Copy link

neodescis commented Dec 31, 2020

I am doing exactly what you're asking. Take a look at the jMuxer library, available here: https://github.com/samirkumardas/jmuxer

Here's the code I'm using to do this. The only down side is I am currently having to hard-code the frame rate.

let debug = true;

function startup() {
    // JMuxer will re-mux the H.264 video stream into the MediaSource object
    const jmuxer = new JMuxer({
        node: 'videoElement',
        mode: 'video',
        flushingTime: 1000,
        fps: 30,
        debug
    });

    // Use Demuxer.TSDemux to demux the MPEG-TS transport stream, then pass the H.264 video stream to JMuxer
    let videoStreamID;
    var demuxer = new Demuxer.TSDemux({ debug });
    demuxer.on('DEMUX_DATA', function(e) {
        // Find the first H.264 stream
        if (!videoStreamID) {
            if (e.stream_type === h264StreamType) {
                videoStreamID = e.pid;
            }
        }
        if (videoStreamID && e.pid === videoStreamID && e.pes && e.pes.data_byte) {
            jmuxer.feed({ video: e.pes.data_byte });
        }
    });

    // Open WebSocket connection to the video relay server
    const ws = new WebSocket(wsURL);
    ws.binaryType = "arraybuffer";
    ws.onmessage = function(event) {
        demuxer.push(event.data, {});
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants