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

There is a simple example? #231

Open
AlgusDark opened this Issue Nov 14, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@AlgusDark

AlgusDark commented Nov 14, 2018

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

@forbesjo

This comment has been minimized.

Contributor

forbesjo commented Nov 16, 2018

We have a debug page (https://github.com/videojs/mux.js/blob/master/debug/index.html) that shows a simple use case but we should document how to use this more clearly. Marking this as a documentation chore, we'll add more docs to make this easier. If you want to take a shot at writing the documentation we would be happy to review and appreciate the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment