Skip to content

Commit ebe1cae

Browse files
committed
Add libplacebo GPU module with render and shader filters
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.
1 parent c34d2b9 commit ebe1cae

11 files changed

Lines changed: 1361 additions & 0 deletions

‎.github/workflows/static-code-analysis.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
--library=cppcheck.cfg
2020
--suppress=ctuOneDefinitionRuleViolation
2121
--suppress=syntaxError:src/modules/xml/common.c
22+
--suppress=syntaxError:src/modules/placebo/filter_placebo_render.c
23+
--suppress=syntaxError:src/modules/placebo/filter_placebo_shader.c
24+
--suppress=syntaxError:src/modules/placebo/gpu_context.c
2225
steps:
2326
- uses: actions/checkout@v4
2427
- name: Install Cppcheck

‎CMakeLists.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ option(MOD_NORMALIZE "Enable Normalize module (GPL)" ON)
3333
option(MOD_OLDFILM "Enable Oldfilm module" ON)
3434
option(MOD_OPENCV "Enable OpenCV module" OFF)
3535
option(MOD_MOVIT "Enable OpenGL module" ON)
36+
option(MOD_PLACEBO "Enable libplacebo GPU module" ON)
3637
option(MOD_PLUS "Enable Plus module" ON)
3738
option(MOD_PLUSGPL "Enable PlusGPL module (GPL)" ON)
3839
option(MOD_QT6 "Enable Qt6 module (GPL)" ON)
@@ -303,6 +304,15 @@ if(MOD_MOVIT)
303304
list(APPEND MLT_SUPPORTED_COMPONENTS movit)
304305
endif()
305306

307+
if(MOD_PLACEBO)
308+
pkg_check_modules(libplacebo IMPORTED_TARGET libplacebo)
309+
if(libplacebo_FOUND)
310+
list(APPEND MLT_SUPPORTED_COMPONENTS placebo)
311+
else()
312+
set(MOD_PLACEBO OFF)
313+
endif()
314+
endif()
315+
306316
if(MOD_PLUS)
307317
pkg_check_modules(libebur128 IMPORTED_TARGET libebur128)
308318
list(APPEND MLT_SUPPORTED_COMPONENTS plus)
@@ -568,6 +578,7 @@ add_feature_info("Module: Normalize" MOD_NORMALIZE "")
568578
add_feature_info("Module: Oldfilm" MOD_OLDFILM "")
569579
add_feature_info("Module: OpenCV" MOD_OPENCV "")
570580
add_feature_info("Module: Movit" MOD_MOVIT "")
581+
add_feature_info("Module: Placebo" MOD_PLACEBO "")
571582
add_feature_info("Module: Plus" MOD_PLUS "")
572583
add_feature_info("Module: PlusGPL" MOD_PLUSGPL "")
573584
add_feature_info("Module: Qt6" MOD_QT6 "")

‎src/modules/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(MOD_MOVIT)
4848
add_subdirectory(movit)
4949
endif()
5050

51+
if(MOD_PLACEBO)
52+
add_subdirectory(placebo)
53+
endif()
54+
5155
if(MOD_PLUS)
5256
add_subdirectory(plus)
5357
endif()

‎src/modules/placebo/CMakeLists.txt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
find_package(PkgConfig REQUIRED)
2+
pkg_check_modules(libplacebo IMPORTED_TARGET libplacebo)
3+
if(NOT libplacebo_FOUND)
4+
return()
5+
endif()
6+
7+
add_library(mltplacebo MODULE
8+
factory.c
9+
gpu_context.c gpu_context.h
10+
filter_placebo_render.c
11+
filter_placebo_shader.c
12+
)
13+
14+
file(GLOB YML "*.yml")
15+
add_custom_target(Other_placebo_Files SOURCES
16+
${YML}
17+
)
18+
19+
include(GenerateExportHeader)
20+
generate_export_header(mltplacebo)
21+
target_compile_options(mltplacebo PRIVATE ${MLT_COMPILE_OPTIONS})
22+
target_include_directories(mltplacebo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
23+
target_link_libraries(mltplacebo PRIVATE mlt PkgConfig::libplacebo)
24+
25+
# Only link D3D11 if libplacebo was built with D3D11 support
26+
include(CheckCSourceCompiles)
27+
set(CMAKE_REQUIRED_INCLUDES ${libplacebo_INCLUDE_DIRS})
28+
check_c_source_compiles("
29+
#include <libplacebo/config.h>
30+
#if !defined(PL_HAVE_D3D11) || !PL_HAVE_D3D11
31+
#error no d3d11
32+
#endif
33+
int main(void) { return 0; }
34+
" PLACEBO_HAS_D3D11)
35+
if(PLACEBO_HAS_D3D11)
36+
target_link_libraries(mltplacebo PRIVATE d3d11 dxgi)
37+
endif()
38+
if(WIN32)
39+
target_link_libraries(mltplacebo PRIVATE shell32 ole32)
40+
endif()
41+
42+
if(MSVC)
43+
target_link_libraries(mltplacebo PRIVATE PThreads4W::PThreads4W)
44+
endif()
45+
46+
set_target_properties(mltplacebo PROPERTIES
47+
LIBRARY_OUTPUT_DIRECTORY "${MLT_MODULE_OUTPUT_DIRECTORY}")
48+
49+
install(TARGETS mltplacebo LIBRARY DESTINATION ${MLT_INSTALL_MODULE_DIR})
50+
51+
install(FILES
52+
filter_placebo_render.yml
53+
filter_placebo_shader.yml
54+
DESTINATION ${MLT_INSTALL_DATA_DIR}/placebo
55+
)

‎src/modules/placebo/factory.c‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* factory.c -- module registration for libplacebo filters
3+
* Copyright (C) 2025 D-Ogi
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "mltplacebo_export.h"
21+
#include <framework/mlt.h>
22+
#include <limits.h>
23+
#include <string.h>
24+
25+
extern mlt_filter filter_placebo_render_init(mlt_profile profile,
26+
mlt_service_type type,
27+
const char *id,
28+
char *arg);
29+
extern mlt_filter filter_placebo_shader_init(mlt_profile profile,
30+
mlt_service_type type,
31+
const char *id,
32+
char *arg);
33+
34+
static mlt_properties metadata(mlt_service_type type, const char *id, void *data)
35+
{
36+
char file[PATH_MAX];
37+
snprintf(file, PATH_MAX, "%s/placebo/%s", mlt_environment("MLT_DATA"), (char *) data);
38+
return mlt_properties_parse_yaml(file);
39+
}
40+
41+
MLTPLACEBO_EXPORT MLT_REPOSITORY
42+
{
43+
MLT_REGISTER(mlt_service_filter_type, "placebo.render", filter_placebo_render_init);
44+
MLT_REGISTER(mlt_service_filter_type, "placebo.shader", filter_placebo_shader_init);
45+
MLT_REGISTER_METADATA(mlt_service_filter_type,
46+
"placebo.render",
47+
metadata,
48+
"filter_placebo_render.yml");
49+
MLT_REGISTER_METADATA(mlt_service_filter_type,
50+
"placebo.shader",
51+
metadata,
52+
"filter_placebo_shader.yml");
53+
}

0 commit comments

Comments
 (0)