Skip to content

There is a simple example? #231

Open
@AlgusDark

Description

@AlgusDark

Is there a working example on how to use mux?

I'm trying to transmux to mp4 on the fly (I'll take care of getting all the segments in order and provide them) but I'm not able to do it in a minimal way

  const fetch = require("node-fetch");
  const muxjs = require("mux.js");

  const buffer = await fetch(
    "http://url.com/segment.ts"
  ).then(response => response.arrayBuffer());

  const uArray = new Uint8Array(buffer);

  var transmuxer = new muxjs.mp4.Transmuxer();
  transmuxer.push(uArray);
  transmuxer.flush();

  transmuxer.on("data", function(segment) {
    segment.data.buffer; // --->
  });

I want to Response segment.data.buffer trough res object from Express.

I've tried to Buffer.from(segment.data.buffer) with something like:

function bufferToStream(buffer) {
    let stream = new Readable();
    stream.push(buffer);
    stream.push(null);
    return stream;
  }

  transmuxer.on("data", function(segment) {
    bufferToStream(Buffer.from(segment.data.buffer)).pipe(res);
  });

I was able to download the mp4 file... but I can't play it. TS file can be played with VLC

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions