restreamer
restreamer copied to clipboard
Latency problems live stream is lagging 8-9 seconds
I use encoding h264 see #128 , but I have a latency problem. I believe it is the clappr player used and not the encoding time. Someone has a solution for this or some more inside? Also why is the "-re" flag set in the live.json config https://github.com/datarhei/restreamer/blob/master/conf/live.json#L90 --> see https://trac.ffmpeg.org/wiki/StreamingGuide#The-reflag For live streaming it shouldn't be used according to the wiki.
Thanks in advance
The encoder could well introduce some latency. Other sources might be the nginx-rtmp module and the player. The nginx-rtmp is configured in a way that it creates chunks of 2 seconds (https://github.com/datarhei/restreamer/blob/master/conf/nginx.conf#L27). The player might buffer 3-4 chunks which would explain the delay.
OT: the "-re" flag is most likely not introducing a delay. But I will check if it can be removed for good.
@ioppermann Thanks for the pointers. I am now down to 1-2 seconds delay which is acceptable to me. The biggest improvement I had with setting the hls_playlist_length to 1s. (https://github.com/datarhei/restreamer/blob/master/conf/nginx.conf#L26) This probably helps with the player not buffering, which was IMO the biggest problem. I still need to read some documentation about it and experiment some more. However this looks very promising lets see how stable the stream will be on the long term.
After a bit of testing and reading below works for me fine, about 1 second delay. Sometimes the stream stops for a second, but that is not an issue for me.
hls_playlist_length 1s;
hls_fragment 500ms;
I am very happy the latency is hugely improved from 8-9 to 1-2 seconds. Now some fine tuning and make everything a bit more robust on my local webpage for serving the streams. :)
@divx118 Thanks a lot for your findings! Did you find some other "fine tuning" to make the stream robust and with very low latency?
@andersla I didn't have any time yet to continue on this, hopefully next weekend. So if you find something I am all ears.
hls_playlist_length 1s;
hls_fragment 500ms;
I did this and got it down to 4 to 5 seconds. Going to try to modify some more settings, any advice is appreciated.
@Wisbell You also have to consider the key frame interval that the camera produces (also known as GOP size). The nginx-rtmp module usually splits the stream at key frames and using hls_fragment
as a guideline, but it is not guaranteed.
You can try to use the hls_max_fragment [x]ms
directive which will force a fragment split even if there's no key frame. This has the consequence that a fragment will most likely not start with a key frame. A player will have to wait for the the first keyframe in order to start decoding the stream. This will again add the latency.
If you have the possibility to configure the key frame (or GOP size) in the camera, then you can tweak the latency there. You can set the interval to e.g. 2 seconds which is usually a good tradeoff between compression and latency.
Any workaround for this?
How much would hls_max_fragment
help?
I didn't try out the hls_max_fragment
option yet. However, I'm not sure how much it will help because players usually wait until they have a complete key frame until they show something. This can be up to the duration of one GOP.
Is there a variable that I can pass to Docker to set these or do I have to build my own image to tweak it?
You can mount in a modified nginx.conf
. Copy the existing one from the repo, apply the tweaks and mount it in by adding -v /path/to/tweaked/nginx.conf:/restreamer/conf/nginx.conf
.
Am i correct that I add that string (after fixing location) to the end of my Docker run command?
It should be part of the docker command where all the other options go. At the end of the docker command is the name of the image. You can add it right before the image name.
E.g.
docker run -d --restart always -e "RS_USERNAME=admin" -e "RS_PASSWORD=datarhei" -p 8080:8080 -v /mnt/restreamer/db:/restreamer/db datarhei/restreamer:latest
becomes
docker run -d --restart always -e "RS_USERNAME=admin" -e "RS_PASSWORD=datarhei" -p 8080:8080 -v /mnt/restreamer/db:/restreamer/db -v /path/to/tweaked/nginx.conf:/restreamer/conf/nginx.conf datarhei/restreamer:latest
Does anyone know how to make this modification in the latest version of the code ? Stuck with an 8-9 second delay and would love to improve it
I'm also stuck on this, I can only get the WebUI to be about 9 seconds delay.
@svenerbeck , I saw this issue was closed. What is the solution to reduce the delay?
@svenerbeck I too would like to know?
i updated the restreamer to version 2 . but now i have up to 30 seconds of latency for some live cameras . can anyone recommand any improvment to do .
I moved to Open streaming platform with a beta branch that uses OvenMediaEngine. This gives me sub second latency.
Hello @devedse do you have a link to the beta branch? Thanks
@apvlv https://github.com/deamos/openstreamingplatform/tree/feature/webrtc-test
Or if you want support for RaspberryPI checkout my Fork.