-
Notifications
You must be signed in to change notification settings - Fork 358
Add libplacebo GPU module with render and shader filters #1201
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
base: master
Are you sure you want to change the base?
Conversation
|
How does this compare with using libplacebo through the existing avfilter? |
|
The main difference is the GPU context lifecycle. The avfilter wrapper creates a new AVFilterGraph per filter instance and vf_libplacebo initializes its own Vulkan device inside that graph. With multiple filters on a timeline you get multiple GPU contexts. The native module uses a process-wide singleton in gpu_context.c so one pl_gpu, one pl_renderer, one pl_dispatch shared across all instances. The frame path is also shorter. The avfilter wrapper does two memcpy round-trips between MLT buffers and AVFrames (line-by-line with linesize conversion), on top of whatever vf_libplacebo does internally for GPU transfer. The native module calls pl_tex_upload/pl_tex_download directly on the MLT image pointer, no intermediate AVFrame. A the most interesting part is the shader filter that doesn't have an avfilter equivalent. It loads mpv .hook files at runtime and checks file mtime on every frame so when the file changes on disk, it re-parses only the pl_hook object while keeping the GPU context alive. This is useful for iterative shader development in for instance an NLE where you want to edit a .hook file in a text editor and see the result on the timeline without restarting anything. The avfilter path would need a full graph rebuild to pick up a changed shader_path. The trade-off is a direct build dependency on libplacebo vs getting it through FFmpeg. The module could be optional so wouldn't affect builds where libplacebo isn't available. Regarding the tests, at this time I don't have solid Linux/MacOS environments to test all the dependencies, but as I read from failed tests the root cause seems to be easy to fix. |
518b737 to
67d2fa2
Compare
New module 'placebo' providing GPU-accelerated video processing via libplacebo. Includes two filters: - placebo.render: GPU scaling, debanding, dithering, and tonemapping with quality presets (fast/default/high_quality) - placebo.shader: Custom mpv-compatible .hook shader support Backend priority: D3D11 (Windows) -> Vulkan -> OpenGL. Vulkan loader is dynamically loaded on Windows when libplacebo is built without vk-proc-addr support. Features: - Singleton GPU context with thread-safe access - Shader cache persistence - Multiple scaling algorithms (ewa_lanczos, lanczos, mitchell, etc.) - Tone mapping (auto, clip, mobius, reinhard, hable, bt.2390, spline) - Graceful fallback to passthrough when no GPU is available The module is enabled by default but skipped automatically when libplacebo is not installed.
67d2fa2 to
ebe1cae
Compare
|
Fixed the MinGW build: |
|
You need to get at least some build workflows to actually build this (not all). For example,
Our codebase generally prefers the macros |
c5189b2 to
8129348
Compare
Use PRIu64/PRId64 from <inttypes.h> instead of %zu/%ld for size logging in the placebo module. Add libplacebo-dev packages to Ubuntu, Debian, and Fedora 42 CI workflows, and mingw-w64-x86_64-libplacebo to the MSYS2 MinGW64 workflow.
8129348 to
35e85eb
Compare
|
Done. Added libplacebo packages to the three workflows, switched to Verified on my fork — all green: MSYS2 MinGW64, Ubuntu 24.04, 22.04, Debian stable/testing/unstable, Fedora 42, 38. |
Break long mlt_log_info() call into multi-line format to match the project's clang-format rules (same style as load_cache above).
Summary
New module
placeboproviding GPU-accelerated video processing via libplacebo:.hookshader support with hot-reload on file changeArchitecture
gpu_context.c) with thread-safe initialization and render lockingvk-proc-addrsupportBuild
Controlled by
MOD_PLACEBOCMake option (default ON). Requireslibplacebovia pkg-config. Optionally links D3D11/DXGI whenPL_HAVE_D3D11is detected at configure time. MSVC builds link PThreads4W.Files (10 total)
CMakeLists.txtMOD_PLACEBOoptionsrc/modules/CMakeLists.txtsrc/modules/placebo/CMakeLists.txtsrc/modules/placebo/factory.csrc/modules/placebo/gpu_context.hsrc/modules/placebo/gpu_context.csrc/modules/placebo/filter_placebo_render.csrc/modules/placebo/filter_placebo_render.ymlsrc/modules/placebo/filter_placebo_shader.csrc/modules/placebo/filter_placebo_shader.ymlTesting
Tested on Windows with D3D11 backend via Kdenlive. Verified:
.hookfiles