MuxLabs / wocket

Example of streaming to an RTMP endpoint from a browser via WebSockets

Home Page:https://ws.mux.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stream is sent in "chunks" with a lag effect?

raed667 opened this issue · comments

commented

First of all thank you for this super interesting project.

This is my first attempt at doing video streaming and its been really helpful with the article and the talk to have a first understanding of the ecosystem and different protocols.

I have ported this project to run with express-wsbut the main concepts are the same.

However, I have noticed that the output video comes in "chunks".

My undrestanding is that mediaRecorder's dataavailable event is triggered whenever the buffer has enough data (~14250kB in my case) and that gets sent through ws.

Is this the expected behavior from this project? And how can we make the output "smoother"

PS: excuse my lack technical words regarding chunks and smoothness of video, i'm not really familiar with the streaming jargon.

PS2: I have tried with both mux URL and also a local docker alfg/nginx-rtmp with the same results.

Thanks for your help

Thanks! The timeslice argument that we pass to the MediaRecorder.start() method determines how many milliseconds apart the dataavailable event will be fired. From MDN

If a timeslice property was passed into the MediaRecorder.start() method that started media capture, a dataavailable event is fired every timeslice milliseconds. That means that each blob will have a specific time duration (except the last blob, which might be shorter, since it would be whatever is left over since the last event). So if the method call looked like this — recorder.start(1000); — the dataavailable event would fire after each second of media capture, and our event handler would be called every second with a blob of media data that's one second long. You can use timeslice alongside MediaRecorder.stop() and MediaRecorder.requestData() to produce multiple same-length blobs plus other shorter blobs as well.

Does that answer your question? Closing this as an issue, but happy to continue the convo.

commented

Thanks for the response, I missed that mediaRecorder.start could take a parameter!

What value would you recommend to have a smooth-ish stream?

Is the output stream you see from the running example smooth? It always has been for me, so I'd start with our settings and then experiment from there.

Also, just a note, make sure your ffmpeg process is keeping up when pushing the stream to the RTMP endpoint. You really want to make sure it's staying at least at 1x real time, and if you're seeing it dropping consistently below that you're going to have a pretty bad experience.