media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
916 stars 132 forks source link

[Linux] GPU Acceleration #819

Open oliver-hrkltz opened 2 weeks ago

oliver-hrkltz commented 2 weeks ago

Hello!

First: Thank you for offering a library which supports all Flutter build targets!

To increase the performance on our kiosk systems I would like to switch from the web build to the linux build. During my tests I noticed that the video playback takes much more CPU if I build the linux version compared to running the web build. And of course the FHD video is also laggy on the linux build.

So I guess the GPU acceleration is not working. The CPU is a Intel N4120 with Intel UHD Graphics running on Kubuntu 24.04.

Linux build:

Cannot load libcuda.so.1
media_kit: VideoOutput: Using H/W rendering.

If I play the video directly in from the terminal with mpv it works fine and the libcuda.so.1 message is not printed.

Can I somehow provide additional information for you to validate if the hardware acceleration is active or not?

abdelaziz-mahdy commented 2 weeks ago

you can disable the hardware acceleration and check the performance if better or not, https://github.com/media-kit/media-kit?tab=readme-ov-file#display-the-video

for the web, web uses native browser video playback so its not the same as any other platform under the hood

abdelaziz-mahdy commented 2 weeks ago

did you follow this https://github.com/media-kit/media-kit?tab=readme-ov-file#gnulinux-1

oliver-hrkltz commented 2 weeks ago

Update: Fixed for me by adding mpv_set_option_string(self->handle, "hwdec", "vaapi") to video_output.cc. It's still missing the cuda package but the acceleration works now.

As a general fix I guess it could be enough to include/read the mpv config file (/etc/mpv/mpv.conf).

abdelaziz-mahdy commented 2 weeks ago

i dont know much about the configuration of mpv, if that works for you can you add a pr so we see if it works on our ci too?

Andrekarma commented 2 weeks ago

Could be something related also to this problem? https://github.com/media-kit/media-kit/issues/552#issuecomment-2095830769

abdelaziz-mahdy commented 2 weeks ago

i dont know but you can test it using

    final videoController = VideoController(player,
        configuration: VideoControllerConfiguration(hwdec: "vaapi"));

@oliver-hrkltz i think it should work for you too instead of changing the video_output.cc