screego / server

screen sharing for developers https://screego.net/
https://app.screego.net
GNU General Public License v3.0
7.62k stars 551 forks source link

Streaming to multiple users results in high CPU usage #160

Open christian-rieger opened 1 year ago

christian-rieger commented 1 year ago

Hello,

I noticed when I am streaming to multiple users that my CPU usage grows proportionally, when I stream to 6 People my CPU is at 100%.

Is it possible that the stream needs to be encoded and encrypted for every viewer? Is there anything I can do to optimize this?

Kind Regards, Chris

jmattheis commented 1 year ago

Yes, the user that shares their screen will encode, encrypt and upload the video stream for each connected user.

The CPU usage can be optimized by reducing the frame rate or resolution (https://github.com/screego/server/issues/84).

Screego could also take responsibility for distributing the videostream, meaning the user that shares will upload the stream to screego, and screego forwards it to all connected users. You could check out Jitsi that already has this functionality.

JulianGro commented 1 year ago

Yes, the user that shares their screen will encode, encrypt and upload the video stream for each connected user.

Am I understanding this right that screengo encodes the video for every viewer instead of just once?

jmattheis commented 1 year ago

I cannot say for sure, because this is done in the browser implementation of WebRTC, but I'd expect it is encoded for every viewer. Basically, screego obtains a MediaStream via MediaDevices#getDisplayMedia and then forwards this stream via RTCPeerConnection#addTrack.

When both peers do the WebRTC handshake, they choose a codec they both support. This means if the video is streamed to multiple peers which support different codecs, the browser has to encode it multiple times with different codecs. If the browser is smart is enough to cache the encoded stream, when another peer uses the same codec I don't know, but given the high cpu usage I'd expect it's encoded again.

xiaguoxin commented 11 months ago

It is true. We test it in our lab, when multiple user connected, the share screen pc almost freezed. If there are any way to fix it?

jmattheis commented 11 months ago

Currenty not, you can use Jitsi or another sharing tool, they proxy the traffic through the server, so the one that shares the screen doesn't have to encode the video multiple times.

wangdemon commented 4 months ago

Currenty not, you can use Jitsi or another sharing tool, they proxy the traffic through the server, so the one that shares the screen doesn't have to encode the video multiple times.

Using other sharing tools,Can you provide an example or link