python-mpv icon indicating copy to clipboard operation
python-mpv copied to clipboard

Scale overlay image size without increasing resolution, to get large pictures and high performance

Open jkazan opened this issue 4 years ago • 8 comments

I am updating an overlay every frame, and to_bytes inside overlay.update is the bottleneck here. I do not mind if the DPI of the overlay image is low, but I need large images to be updated fast.

A fix for this would be fantastic!

Thanks for all the good work!

jkazan avatar Sep 13 '20 08:09 jkazan

I am fairly sure that this is not currently possible, since libmpv does not seem to expose any API to do that. You could try to optimize ImageOverlay's update() implementation, but I haven't looked into that more closely yet.

I think a better way to get the same result might be to use mpv's OpenGL API from python, and manually render the overlay on top of mpv's framebuffer using OpenGL.

jaseg avatar Sep 13 '20 08:09 jaseg

I found the --drm-draw-surface-size paramter at https://mpv.io/manual/master/#video-output-drivers Isn't this what I am looking for ? However, whatever I set the resolution to, nothing changes. Perhaps I am misinterpreting? My understanding is that the overlay resolution will be <WxH> and then scaled up to the resolution of the mpv window.

Could you please clarify this? I really appreciate your help!

jkazan avatar Sep 14 '20 12:09 jkazan

That option is specific to the DRM (Linux Direct Rendering Manager) video output driver. Unless you are rendering on a console linux setup that does not have X11 or wayland you will use a different video output driver such as gpu or direct3d.

jaseg avatar Sep 14 '20 12:09 jaseg

I see. Any chance of doing the same thing with X11?

jkazan avatar Sep 14 '20 12:09 jkazan

Well, using OpenGL would basically amount to this. Via the gpu video output driver, OpenGL is also the default video output anyway, so integrating against libmpv's OpenGL API should not pose any significant compatibility issues either (at least for desktops/laptops, rpi&co might not perform as well).

jaseg avatar Sep 14 '20 12:09 jaseg

Cool, I'll look into it. Thanks a lot for your quick replies!

jkazan avatar Sep 14 '20 12:09 jkazan

It seems I can use the property vf="gpu=400:225", but that only affects the video, not the overlay. Any ideas?

jkazan avatar Sep 14 '20 19:09 jkazan

The only suggestion I can come up with is to use opengl to properly control this. For an opengl/python-mpv example, please have a look at https://gist.github.com/jaseg/657e8ecca3267c0d82ec85d40f423caa and https://gist.github.com/cosven/b313de2acce1b7e15afda263779c0afc

vf=gpu inserts an OpenGL/GPU video filter stage. This is run before the video is passed on to the video output driver, which is pasting in any overlays. In your case, that filter stage does nothing and just passes on the framebuffer that it gets at the resolution you specify. The --glsl-shaders option offers a weird command line/option interface with that but I would really advise against that.

jaseg avatar Sep 14 '20 20:09 jaseg