Integrate libmpv for video playing

167 views
Skip to first unread message

Kelvin Ng

unread,
Jan 10, 2022, 7:28:39 PM1/10/22
to Chromium-dev
Do you think it makes sense to use libmpv to implement WebMediaPlayer for playing video? It seems possible to me. Basically we can ask libmpv to render a frame in a texture. Then we can wrap it as a VideoFrame and let cc::VideoLayer grab it.

Motivations:

Problematic video playing on Linux:
Chromium video playing is problematic on Linux. Some people cannot enable hardware decode acceleration. I can enable hardware decode acceleration, but it produces very poor video quality (video is blurred, color is slightly off, and is distorted like 1920x1080 will be played at 1920x1040). These are well known problems of VAAPI rendering (decoding is fine, rendering is not). In contrast, libmpv uses VAAPI to decode but OpenGL to render. (If you force mpv to use VAAPI to render, mpv will show similar problems, so it is not a Chromium bug)

Configurable video playing:
I care most about upscaling filter. If you play 1920x1080 video on a 4K monitor, Chromium will blur the video due to the poor upscaling algorithm used (whether using VAAPI or software). libmpv allows you to choose or even add an upscaling algorithm (even machine learning-based algorithms can be used). libmpv also allows other configurations.

To solve the first problem, we can definitely just re-implement the VAAPI decoder so that it only uses VAAPI to decode and not render. However, the second motivation justifies the use of libmpv for its flexibility.

Also, I think media playing is really a separate thing that Chromium should not care too much about. Offloading to a "professional" media playing library seems a reasonable choice to me.

Any comments? I am interested in working on it if it has a reasonable chance to get merged, at least as an option that can be enabled in chrome://flags.

Kelvin Ng

unread,
Jan 13, 2022, 7:12:12 PM1/13/22
to Chromium-dev, Kelvin Ng
I already have an idea on how to implement that, but as a VideoRenderer instead of WebMediaPlayer. So, MPV will only decode and render images to a texture. Normally MPV will push frames according to its own timer, but now we will let the compositor to pull frames at its own pace. This is an abuse of MPV but it should work.

However, the problem is that Chromium may apply a bunch of shaders inside Viz. I can hack the VideoFrameProvider to provide MPV with the final display size in physical pixels so that MPV can scale the frames properly and avoid activating Chromium's scaling shader. However, there are still potentially other shaders that I don't know. I am fine with Chromium using its own shaders to react to CSS styling (like blurring), but I want to avoid Chromium using general shaders (like ditchering and those for color management?) because these will also be applied by MPV and many of these are not idempotent. Can anyone tell me if Chromium actually apply those shaders?

If Chromium indeed applies those shaders, I am thinking to make a MPVRenderPass which simply draw exactly what MPV provides, but that only helps if those shaders are applied during the same pass/quad of drawing the video frame. If afterwards a render pass takes the whole thing from the previous pass and apply those shaders, I am afraid there is no way to bypass it.

sL1pKn07 SpinFlo

unread,
Jan 28, 2022, 11:03:21 AM1/28/22
to nkwk...@gmail.com, Chromium-dev
Hi!

when i've read 'libmpv', i got instantly big boner!

PLEASE, DO IT!

this can solve the problem with play multimedia with HW acceleration (mpv can enable HW decoding with VAAPI or NVENC(Cuda), or in near future, with Vulkan!)

greetings

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/386abd8e-0325-4135-99ab-c6a6312ba8ban%40chromium.org.
Reply all
Reply to author
Forward
0 new messages