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

Live streaming support #12

Closed
rafael2k opened this issue Mar 12, 2023 · 5 comments
Closed

Live streaming support #12

rafael2k opened this issue Mar 12, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rafael2k
Copy link

Would it be possible to get chunks of muxed data for live streaming? I use webm streaming created from ffmpeg (to an icecast2 server) and it works fine (I can play in a html5 video ou audio tag without problem), even thou the webm standard was not really conceived for live streaming...

@Vanilagy
Copy link
Owner

There already is a streaming target, documented in README, which is a callback that regularly gets called as new muxed chunks become available. Only gotcha is that the offsets it gets called with are not monotonically increasing (since it goes back to rewrite old parts), which is not what you'd want for streaming. But, if you ignored those, have you tried using that for streaming?

If it doesn't work, I could add an option that ensures that all data is written sequentially.

@rafael2k
Copy link
Author

Sorry I did not realized that. I'll take a look and test. But I don't know if I understand about the offsets. I control the offsets written to the media chunks block in the code, right?

@Vanilagy
Copy link
Owner

Vanilagy commented Mar 13, 2023

The offset is the byte offset at which the data passed is written. It works like this, remember:

let muxer = new WebMMuxer({
    target: (data: Uint8Array, offset: number, done: boolean) => {
        // Do something with the data
    },
    ...
});

Every time the function is called, you'll get some bytes in form of a Uint8Array in data, and an integer byte offset in offset. This means that you'll have to write the bytes in data to your location (final "file") at position offset. If you're just interested in live streaming, you can try to ignore offset and simply send everything that you receive in data. However, remember that the writing is not sequential, since I jump back and forth to patch things I already wrote. That's why, if you want to live stream, you'll need to ignore any call of target with an offset smaller than the maximum of what you've received.

Again, you can see if this works. WebM actually was designed with live-streaming in mind, it just required me to mux it slightly differently (never jump back, set "size" fields to unknown, etc.). If it doesn't work for you as-is, I can try adding a mode for it!

@rafael2k
Copy link
Author

Got it, thanks for the explanation. I think I can connect to an icecast2 server directly using PUT (I'm using this [1] as reference). Lemme see if I manage to write something fast to test live streaming.

[1] https://github.com/social-dist0rtion-protocol/wasm-stream/blob/master/src/icecast.js

@Vanilagy
Copy link
Owner

How's it going? Do you still need something, or can I close this issue for now?

@Vanilagy Vanilagy closed this as completed Apr 1, 2023
@Vanilagy Vanilagy added enhancement New feature or request help wanted Extra attention is needed labels Apr 4, 2023
@happylinks happylinks mentioned this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants