1

I am trying to stream live video from a Pi to multiple devices. Since the Pi is connected to a WiFi with very bad signal, I would like it to only stream to one device (proxy-server). This device should then distribute the stream to other devices.

I tried to write my own python scripts to achieve this. The server just reads the data from a socket and distributes it to multiple connected client sockets. The clients read the data from their sockets and write it to a subprocess pipe, like in this tutorial: https://picamera.readthedocs.io/en/release-1.13/recipes1.html#recording-to-a-network-stream

Although this solution works, it comes with various restrictions for me:

  • The solution does not seem to work with VLC. Every view seconds the VLC starts to buffer. After Buffering it plays the video again for some seconds before buffering again. I think that the VLC somehow plays the video faster than it is recorded. Maybe someone has a solution to fix this?
  • The solution works perfectly with MPlayer. Unfortunately, MPlayer does not seem to work on newer Raspian distributions (it has problems with some codec library). I planned one of the clients to be raspberry, so this does not work. In Addition, MPlayer is old and not supported anymore as far as I know.
  • The solution does not work with MPV (which seems to be the successor of MPlayer. When I call player.stdin.write(data) for MPV I always get a broken pipe exception (Maybe the player does not support this? ).

Sorry if my problem seems really simple. I am new to writing code for streams (network streams, file streams and the input stream of the player).

I really appreciate any ideas for my streaming problem or maybe someone can help me fix the problem in VLC or MPV, which would also solve the situation for me.

Another solution could be a VLC RTSP stream, but I could not work out a way to forward it on a server.

Thanks in advance!

1 Answer 1

2

Is there a reason why you want to stream via your Python script, as opposed to streaming to VLC directly?

[socket] -> Python -> [pipe] -> VLC

vs

[socket] -> VLC

You just add another interface (a pipe between Python and VLC) which adds some delay and jitter and doesn't seem to do any useful processing. Especially since you seem to read multiples of 1024 bytes which on one hand produces significant overhead, and on the other hand leaves VLC waiting for the last few bytes of data until the next IP packet arrives. This comes in addition to any data fragmentation caused by your proxy server, it it's implemented in the same way.

You could try to reduce the VLC cache time to a very small value (e.g 50 ms) and see if the playback gets better. Or perhaps increasing the cache size will result in a single buffering event followed by an acceptably long uninterrupted playback.

Personally, the first thing I would try is to get rid of your Python scripts (perhaps replace your proxy server with socat) and see if the playback gets better.

1
  • Thank you for your answer! How can i achieve [socket] -> VLC? I currently have a socket in python so I am not really sure what you mean. Jan 13, 2020 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.