131 / h264-live-player

A live h264 player for the browser (ideal for raspberrypi / raspicam )
MIT License
1.08k stars 251 forks source link

Question: Client Connecting to Stream In Progress #47

Closed lreading closed 6 years ago

lreading commented 6 years ago

Please forgive me if this isn't the best place to ask:

I'd like to have a single stream from a pi that many clients can connect to without having to restart the stream. I've been using the server-rpi.js as a starting point.

For more context: I have the pi connect to a WebSocket server which just broadcasts the data to all connected clients as a sort of proxy. My goal is to have 1 connection from the pi to the proxy, and many connections to the proxy. If someone knows of an existing implementation like this, that'd be super helpful. :)

I'm only able to render video on the client if it is connected to the WebSocket proxy prior to the pi connecting. If it connects after the pi has begun streaming data, I only get a blank canvas.

I am still working my way through https://www.ietf.org/rfc/rfc3984.txt to understand what is happening under the hood. I'm thinking this may have to do with the Packetization mode and/or the headers, but I have yet to fully understand the document.

My questions:

Thanks for the awesome lib!

lreading commented 6 years ago

Disclaimer: I'm still not an expert on the topic, so corrections are welcome, especially if it benefits future readers.

Raspivid has an option to insert inline headers to the stream (-ih). I'm assuming the decoder is reusing the initial header packets that are sent, which is why the new connection could not render after the stream had started. This is hinted at in the RFC (page 4):

"It may even be possible that they are never transmitted but are fixed by an application design specification."

The solution was to just add the "-ih" flag when starting raspivid: const streamer = childProcess.spawn('raspivid', ['-t', '0', '-o', '-', '-w', options.width, '-h', options.height, '-fps', options.fps, '-pf', 'baseline', '-ih']);

Thanks again for the awesome library. As I learn more, I'd love to contribute where I can. 👍