Skip to content

Conversation

@D-Ogi
Copy link

@D-Ogi D-Ogi commented Feb 1, 2026

Summary

New module placebo providing GPU-accelerated video processing via libplacebo:

  • placebo.render — GPU scaling (ewa_lanczos, lanczos, mitchell, etc.), debanding, dithering (blue noise, ordered LUT), and tonemapping (auto, clip, mobius, reinhard, hable, bt.2390, spline) with quality presets (fast/default/high_quality)
  • placebo.shader — Custom mpv-compatible .hook shader support with hot-reload on file change

Architecture

  • Singleton GPU context (gpu_context.c) with thread-safe initialization and render locking
  • Backend priority: D3D11 (Windows) → Vulkan → OpenGL
  • Vulkan loader dynamically loaded on Windows when libplacebo is built without vk-proc-addr support
  • Shader cache persisted to disk for faster subsequent startups
  • Graceful passthrough when no GPU is available

Build

Controlled by MOD_PLACEBO CMake option (default ON). Requires libplacebo via pkg-config. Optionally links D3D11/DXGI when PL_HAVE_D3D11 is detected at configure time. MSVC builds link PThreads4W.

Files (10 total)

File Description
CMakeLists.txt +1 line: MOD_PLACEBO option
src/modules/CMakeLists.txt +4 lines: placebo subdirectory
src/modules/placebo/CMakeLists.txt Module build config
src/modules/placebo/factory.c Module registration
src/modules/placebo/gpu_context.h GPU lifecycle API
src/modules/placebo/gpu_context.c Singleton GPU init (D3D11/Vulkan/OpenGL)
src/modules/placebo/filter_placebo_render.c Render filter implementation
src/modules/placebo/filter_placebo_render.yml Render filter metadata
src/modules/placebo/filter_placebo_shader.c Shader filter implementation
src/modules/placebo/filter_placebo_shader.yml Shader filter metadata

Testing

Tested on Windows with D3D11 backend via Kdenlive. Verified:

  • GPU initialization and fallback chain
  • Render filter with default/fast/high_quality presets
  • Shader filter with Anime4K and FSRCNNX .hook files
  • Shader hot-reload on file modification
  • Graceful passthrough when GPU is unavailable
  • Shader cache persistence across sessions
  • Thread safety under concurrent filter instances

@ddennedy
Copy link
Member

ddennedy commented Feb 1, 2026

How does this compare with using libplacebo through the existing avfilter?

@D-Ogi
Copy link
Author

D-Ogi commented Feb 1, 2026

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.

@D-Ogi D-Ogi force-pushed the feature/placebo-module branch 2 times, most recently from 518b737 to 67d2fa2 Compare February 1, 2026 21:33
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.
@D-Ogi D-Ogi force-pushed the feature/placebo-module branch from 67d2fa2 to ebe1cae Compare February 1, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants