discord-screenaudio icon indicating copy to clipboard operation
discord-screenaudio copied to clipboard

Stream FPS suffers immensely when streaming intensive games

Open ockerman0 opened this issue 2 years ago • 23 comments

I took interest in this as I like to stream games to my friend group sometimes but the official client still doesn't support audio. For 3/4 of the games I tested, the stream's FPS was extremely low when wandering in areas that otherwise show up just fine on the official client. As expected, choosing lower streaming resolutions helps alleviate this, but it doesn't go away completely.

For reference, I am running this on Arch Linux on kernel 5.19.9, client was built from the AUR.

ockerman0 avatar Sep 21 '22 20:09 ockerman0

I think it's because lack of hardware acceleration on discord web version and desktop version on linux.

Maciejka1 avatar Sep 23 '22 20:09 Maciejka1

Just wanted to raise this as well. CPU usage increases from 30 to around 75% when streaming, so GPU is indeed unused. (So playing a game becomes unbearable, as the actual framerate is like 30 instead of 120fps. Oddly enough mangohud stays around 110, which the input lag alone disproves)

Is there a way to enable hardware acceleration? Since it is electron/chrome based, are there flags one can enable for VA-API or whatever it is called?

SvdB-nonp avatar Sep 24 '22 07:09 SvdB-nonp

Judging from https://wiki.qt.io/QtWebEngine/VideoAcceleration I don't think this can be fixed easily, but I could be wrong

maltejur avatar Sep 24 '22 10:09 maltejur

i am not very good at any of this but from the documentation in the QtWebEngine wiki maltejur sent there is this https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/209204/ Edit: Looking at the link maltejur sent better, this is talking about 2020, and qt 5.8 (?) maybe useful link is https://github.com/GarageGames/Qt/tree/master/qt-5/qtwebengine/src/3rdparty/chromium/content/common/gpu/media i can see there is some things for va-api support, but again, i am very bad at this so take that with a grain of salt

Kiamrt avatar Sep 25 '22 10:09 Kiamrt

I feel as though this issue should get more attention, this can be a real deal breaker even if there is working audio. For viewers, having the stream at an uncomfortable stutter dependent on hardware can be a real drag for watch-ability.

Sirmentio avatar Oct 15 '22 17:10 Sirmentio

Hm judging from the qt bug report there is not much I can do about that. But I have found one promising solution/hack in a issue from qutebrowser.

I have put my code on the testing_hardware_accel branch. Can somebody who experiences lags try out that code and see if it gets any better?

maltejur avatar Oct 15 '22 18:10 maltejur

Hm judging from the qt bug report there is not much I can do about that. But I have found one promising solution/hack in a issue from qutebrowser.

I have put my code on the testing_hardware_accel branch. Can somebody who experiences lags try out that code and see if it gets any better?

Hi, I've just tried the client, built from that branch. There seems to be no difference in performance between it and the main branch, the performance drop still persists.

ockerman0 avatar Oct 16 '22 13:10 ockerman0

I'll have to test how it works when I can screenshare. Using KDE+Wayland just causes a blank screen, so I have to use X.Org

Sirmentio avatar Oct 16 '22 21:10 Sirmentio

I have tested it myself, and from people viewing my stream, it's still very choppy.

Sirmentio avatar Oct 16 '22 21:10 Sirmentio

Hm ok then there is nothing I can really do.

maltejur avatar Oct 18 '22 21:10 maltejur

uhhh i checked out the flags that you added, but some are missing for example those are some of the ones i use with my chrome/chromium and without them decoding doesnt work "--ignore-gpu-blacklist --enable-gpu-rasterization --enable-smooth-scrolling --disable-software-rasterizer" "--disable-features=UseOzonePlatform,UseChromeOSDirectVideoDecoder,UseChromeOSDirectVideoEncoder" "--enable-gpu-compositing --enable-drdc --enable-raw-draw" "--disable-gpu-driver-bug-workarounds --disable-gpu-driver-workarounds" "--enable-native-gpu-memory-buffers --num-raster-threads=8 --enable-accelerated-2d-canvas" "--enable-features=WebRTCPipeWireCapturer,VaapiVideoEncoder,VaapiVideoDecoder,Vulkan,CanvasOopRasterization" "--enable-accelerated-video-decode --enable-accelerated-mjpeg-decode --enable-accelerated-video-encode" i'm pretty sure those are needed for it to somehow work correct me if i'm wrong, also by doing this you now use your gpu to watch streams too technically, and u disable software rasterization so you use your gpu

Kiamrt avatar Oct 20 '22 13:10 Kiamrt

You can test if you can get hardware acceleration running by setting QTWEBENGINE_CHROMIUM_FLAGS to those chromium flags.

maltejur avatar Oct 22 '22 21:10 maltejur

The interesting part is that even with what I consider high end specs my stream also has complaints of lag from viewers at times even just in the browser playing video let alone gaming.

CPU: AMD Ryzen 5800X
GPU: AMD 6700XT
Using Flatpak discord-screenaudio

rowbawts avatar Oct 25 '22 23:10 rowbawts

@rowbawts are you sure this is not caused by your internet connection? Do you have a high CPU usage? If I stream 1080p on the official discord client my stream is also quite laggy.

maltejur avatar Oct 26 '22 20:10 maltejur

@rowbawts are you sure this is not caused by your internet connection? Do you have a high CPU usage? If I stream 1080p on the official discord client my stream is also quite laggy.

Edit: I just tested screen sharing from my Macbook and it has no issue so it's not my network and my desktop running Windows 11 also has no issues so I don't think it's the hardware.

If I use OBS I have no issues. The screenshot below is CPU usage while streaming with discord-screenaudio.

image

image

rowbawts avatar Oct 26 '22 21:10 rowbawts

@rowbawts are you streaming on the same resolution and FPS in the official client and here?

But if this is indeed not the issue I see that something should be done here, I just don't know what. The official Qt wiki states that video acceleration is not supported and testing out some command line flags has not worked for me either.

maltejur avatar Oct 28 '22 17:10 maltejur

@maltejur Yeah every time I do 1080p 60fps but even when trying other lower settings the same issue occurs. But I completely understand, If you end up figuring out a way to enable hw accel it should definitely improve.

rowbawts avatar Oct 29 '22 00:10 rowbawts

image i got hardware acceleration to work, sadly for decoding only, those are the flags i used, also bear in mind i'm using the va-api feature

curious how many of the flags are getting ignored, also, if i change num-raster-threads it doesn't get any higher

qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blacklist --enable-gpu-rasterization " "--enable-accelerated-video-decode --enable-accelerated-video-encode " "--enable-native-gpu-memory-buffers --num-raster-threads=4 " "--enable-features=WebRTCPipeWireCapturer,VaapiVideoEncoder,VaapiVideoDecoder " "--disable-features=UseOzonePlatform,UseChromeOSDirectVideoDecoder,UseChromeOSDirectVideoEncoder " + qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));

I tested this by watching a video with lowered cpu clock speeds so usage would be higher, and monitoring my gpu through green with envy, sadly as i said this only works for hardware decoding, it seems

Kiamrt avatar Nov 05 '22 13:11 Kiamrt

I can't figure how could I set flags.

AsakaJX avatar Apr 29 '23 16:04 AsakaJX

Not a solution, but firefox works way better for me with intensive games. Inspired by this project, I created this extension for firefox. It is not packaged for any distro, I'm open to contributions though!

IceDBorn avatar Jul 10 '23 00:07 IceDBorn

Still no news on working GPU hardware acceleration?

TibixDev avatar Oct 15 '23 23:10 TibixDev

Two things I'm curious about. (Wayland Specific)

  1. OBS somehow is able to capture the screen with no impact to the game, and at a high refresh rate. How?
  2. Maybe discord-screenaudio can create a local rtmp server, and use the contents from there to stream to discord? That way we can use OBS to actually capture the frames (?)

aaomidi avatar Nov 12 '23 21:11 aaomidi

Things got a little weird lately.

flatpak vanilla discord com.discordapp.Discord started is working for screensharing video from individual games/windows quite well. Hardware Acceleration and video codec OPENH264 are enabled - which results in a smooth video stream. Problem is no audio.

flatpak discord-screenaudio while the audio is working, does not show hardware acceleration. Problem is unwatchable choppy video.

Too bad I can't get both, smooth video and audio. I don't know enough about what's going on, but for video I need hardware acceleration / H264 to be watchable.

I've tried this in both X11/wayland scenarios. GPU is AMD 5700 XT

image

chrisbrasington avatar Dec 23 '23 23:12 chrisbrasington