Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video: Hardware Acceleration #345

Open
alexmercerind opened this issue Dec 1, 2022 · 1 comment
Open

Video: Hardware Acceleration #345

alexmercerind opened this issue Dec 1, 2022 · 1 comment
Assignees
Labels
critical The bug has high priority improvement Improvement over already existing feature or code

Comments

@alexmercerind
Copy link
Owner

alexmercerind commented Dec 1, 2022

How is current video rendering?

Currently, whenever you show a video using Video widget from package:dart_vlc, it produces redundant load on your CPU.
It is because every frame is copied from GPU back to RAM through CPU for rendering inside Flutter i.e. no hardware-acceleration.
This load on CPU increases significantly with higher resolution or higher FPS videos.

This still works fine -ish with 720p videos (bearable CPU load).

What is hardware acceleration?

From Google:

Hardware acceleration is the use of computer hardware designed to perform specific functions more efficiently when compared to software running on a general-purpose central processing unit.

Playing a video should make use of dedicated hardware i.e. GPU (and not CPU). CPU is for general-purpose computation, not copying frames/buffers or rendering things efficiently. As discussed above, since every video frame is copied from GPU back to RAM through CPU for rendering inside Flutter, redundant CPU load is seen. This also increases the power usage (battery consumption).

Currently, 720p videos result in bearable CPU load & work fine -ish. Higher than that, high CPU usage.

NOTE: If you are showing the Video in a small part of the UI, you can limit the dimensions of each frame manually.
This will reduce CPU usage & give you finer control to tweak the performance.

Player player = Player(id: 0, videoDimensions: const VideoDimensions(640, 360));

Why is hardware acceleration not supported (yet)?

First of all, because this is way too complex to be part of someone's hobby. A funding is necessary here.

Both, due to Flutter & libVLC's limitations at that time.

When & how will be hardware accelerated video playback implemented?

Fortunately, package:dart_vlc & my work in this regard is now sponsored by Stream.

This is a concern for Windows & Linux currently.
Scope of work may be increased as required, however package:video_player already seems to have hardware acceleration.
Maybe I will add support to package:video_player itself at some point.


Stream Chat

Rapidly ship in-app messaging with Stream's highly reliable chat infrastructure and feature-rich SDKs, including Flutter!

Try the Flutter Chat tutorial


I made a POC implementation (posted on my Twitter) showing hardware-accelerated video rendering inside Flutter.
It is using libmpv & ANGLE based Direct3D & open-gl interop.
Notice minimal CPU 2 % - 5% usage. Slight usage can still be seen due to logging/flushing etc. for debugging. It will be improved.
Same would have caused about 20-25% with package:dart_vlc (even more with higher resolution & FPS videos).

I have decided to use libmpv because it has API for rendering video output using open-gl.
Since, this package has everything specifically around VLC, it makes no sense to work on it here.

Thus, expect a new package really-really soon with hardware accelerated video playback. Other than just hardware-accelerated video embedding, it has things like metadata / tags reader, shifting support, pitch shifting, volume boost, dynamic playlists & native OS controls etc. out-of-the-box along-side basic features. Audio-only support is ready & used in Harmonoid: A Material Design-led music player to play & manage music library.
Most importantly: It is far smaller in size compared to package:dart_vlc, stable & even supports Windows 7.

Switching to libmpv does not mean that I do not like VLC or the awesome work that developers have done on it. It is still the best of best (& my preferred) media player, which I have installed on every device I own.
However, from the library / plugin standpoint, I'm not quite satisfied.

libmpv+flutter.mp4

Thanks!


You may subscribe to the issue for updates.

@alexmercerind alexmercerind added improvement Improvement over already existing feature or code critical The bug has high priority labels Dec 1, 2022
@alexmercerind alexmercerind self-assigned this Dec 1, 2022
@alexmercerind alexmercerind pinned this issue Dec 1, 2022
@alexmercerind alexmercerind mentioned this issue Dec 1, 2022
2 tasks
@alexmercerind
Copy link
Owner Author

package:media_kit is now public!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
critical The bug has high priority improvement Improvement over already existing feature or code
Projects
None yet
Development

No branches or pull requests

1 participant