m1k1o / neko

A self hosted virtual browser that runs in docker and uses WebRTC.
https://neko.m1k1o.net/
Apache License 2.0
7.17k stars 526 forks source link

VP8 freeze/fps drop issue. #156

Open Hammyboo opened 2 years ago

Hammyboo commented 2 years ago

I first met this problem on Intel servers, but then I moved to AMD and it is still the same, so I think it comes with Neko. The issue is that if you use VP8 codec the screen will freeze every few mins, lets say every 16 mins, sometimes an hour sometimes less, its pretty random. the screen stops but the sound keeps on going. here is a video of how it looks like : https://www.youtube.com/watch?v=HQxbWX9TPlo

m1k1o commented 2 years ago

I can confirm that i experience this sometimes. Thought always its some network issue but if that is reproducible it will be worth looking into that.

m1k1o commented 2 years ago

Transfered to neko from neko-rooms as this is issue with the room itself, not with neko-rooms.

mbattista commented 2 years ago

Do all "watchers" get the freeze at the same time? If so, perhaps the buffer size of the VP8 needs more fine tuning for server environments.

https://github.com/m1k1o/neko/blob/master/server/internal/gst/gst.go#L109

pipelineStr = fmt.Sprintf(videoSrc+"vp8enc target-bitrate=%d cpu-used=4 end-usage=cbr threads=4 deadline=1 undershoot=95 buffer-size=%d buffer-initial-size=%d buffer-optimal-size=%d keyframe-max-dist=180 min-quantizer=3 max-quantizer=40"+pipelineStr, pipelineDevice, fps, bitrate*1000, bitrate*6, bitrate*4, bitrate*5)

If not, can you post the graphs of chrome://webrtc-internals/ of the neko video stream?

Hammyboo commented 2 years ago

Hey mbattista, This bug is on all neko versions, not only me, you can recreate it yourself if you want, and it happens for solo and party sessions. I have installed neko on several servers and different versions and it still happened on all of them, but i will also apply the pipeline you suggested and check what happens.

m1k1o commented 2 years ago

I tried to change keyframe-max-dist from 180 to 25. For 25fps then it freezes only for about 1sec, while when set to 180 it can be up to 7sec. So it looks like it misses keyframe at some point and then waits for the next one while screen is frozen.

mbattista commented 2 years ago

Changing the keyframe-max-dist will shorten the freeze, since the keyframe will trigger a full reload.

But the main goal should be to have no freeze at all, and not shorter freezes.

vpxenc  input_640_480_15fps.yuv -o output_vp8.webm \
  --codec=vp8 --i420 -w 640 -h 480 -p 1 -t 4 \
  --rt --cpu-used=4 --end-usage=cbr --target-bitrate=500 \
  --fps=15000/1001 --undershoot-pct=95 \
  --buf-sz=6000 --buf-initial-sz=4000 --buf-optimal-sz=5000 -v \
  --kf-max-dist=999999 \
  --min-q=4 --max-q=56

This would be an example pipeline from the webm project https://www.webmproject.org/docs/encoder-parameters/

dragonballa commented 2 years ago

any updates on this?

dragonballa commented 2 years ago

I tried to change keyframe-max-dist from 180 to 25. For 25fps then it freezes only for about 1sec, while when set to 180 it can be up to 7sec. So it looks like it misses keyframe at some point and then waits for the next one while screen is frozen.

where do you change this value? and is it apply to firefox?

m1k1o commented 2 years ago

By changing that value we get sometimes 1s freeze but that is unnoticeable and way beter than previous 7sec. Although, the original problem still persists.

@dragonballa here: https://github.com/m1k1o/neko/blob/c48309b6485a816789589ff7115a9bc4e4340000/server/internal/gst/gst.go#L121

It applies to the neko base, meaning for all brwosers.