Go to the documentation of this file.
25 #include <libplacebo/renderer.h>
26 #include <libplacebo/utils/libav.h>
27 #include <libplacebo/vulkan.h>
146 av_log(log_ctx, av_lev,
"%s\n", msg);
152 const struct pl_hook *hook;
154 hook = pl_mpv_user_shader_parse(
s->gpu, shader,
len);
160 s->hooks[
s->num_hooks++] = hook;
165 const struct pl_filter_config **opt,
168 const struct pl_filter_preset *
preset;
169 if (!strcmp(
name,
"help")) {
192 s->log = pl_log_create(PL_API_VER, pl_log_params(
214 s->vulkan = pl_vulkan_import(
s->log, pl_vulkan_import_params(
215 .instance = hwctx->
inst,
223 .index = hwctx->queue_family_index,
224 .count = hwctx->nb_graphics_queues,
227 .index = hwctx->queue_family_comp_index,
228 .count = hwctx->nb_comp_queues,
231 .index = hwctx->queue_family_tx_index,
232 .count = hwctx->nb_tx_queues,
235 .max_api_version = VK_API_VERSION_1_2,
245 s->gpu =
s->vulkan->gpu;
246 s->renderer = pl_renderer_create(
s->log,
s->gpu);
249 if (
s->shader_bin_len)
252 if (
s->shader_path &&
s->shader_path[0]) {
269 for (
int i = 0;
i <
s->num_hooks;
i++)
270 pl_mpv_user_shader_destroy(&
s->hooks[
i]);
271 pl_renderer_destroy(&
s->renderer);
272 pl_vulkan_destroy(&
s->vulkan);
273 pl_log_destroy(&
s->log);
283 struct pl_render_params params;
284 struct pl_frame image, target;
285 ok = pl_map_avframe_ex(
s->gpu, &image, pl_avframe_params(
287 .map_dovi =
s->apply_dovi,
290 ok &= pl_map_avframe_ex(
s->gpu, &target, pl_avframe_params(
300 if (!
s->apply_filmgrain)
301 image.film_grain.type = PL_FILM_GRAIN_NONE;
303 if (
s->target_sar.num) {
304 float aspect = pl_rect2df_aspect(&target.crop) *
av_q2d(
s->target_sar);
305 pl_rect2df_aspect_set(&target.crop, aspect,
s->pad_crop_ratio);
309 params = (
struct pl_render_params) {
311 .lut_entries =
s->lut_entries,
312 .antiringing_strength =
s->antiringing,
314 .deband_params = !
s->deband ?
NULL : pl_deband_params(
315 .iterations =
s->deband_iterations,
316 .threshold =
s->deband_threshold,
317 .radius =
s->deband_radius,
318 .grain =
s->deband_grain,
321 .sigmoid_params =
s->sigmoid ? &pl_sigmoid_default_params :
NULL,
323 .color_adjustment = &(
struct pl_color_adjustment) {
324 .brightness =
s->brightness,
325 .contrast =
s->contrast,
326 .saturation =
s->saturation,
331 .peak_detect_params = !
s->peakdetect ?
NULL : pl_peak_detect_params(
332 .smoothing_period =
s->smoothing,
333 .minimum_peak =
s->min_peak,
334 .scene_threshold_low =
s->scene_low,
335 .scene_threshold_high =
s->scene_high,
336 .overshoot_margin =
s->overshoot,
339 .color_map_params = pl_color_map_params(
341 .tone_mapping_algo =
s->tonemapping,
342 .tone_mapping_param =
s->tonemapping_param,
343 .desaturation_strength =
s->desat_str,
344 .desaturation_exponent =
s->desat_exp,
345 .desaturation_base =
s->desat_base,
346 .max_boost =
s->max_boost,
347 .gamut_warning =
s->gamut_warning,
348 .gamut_clipping =
s->gamut_clipping,
351 .dither_params =
s->dithering < 0 ?
NULL : pl_dither_params(
352 .method =
s->dithering,
353 .lut_size =
s->dither_lut_size,
354 .temporal =
s->dither_temporal,
357 .cone_params = !
s->cones ?
NULL : pl_cone_params(
359 .strength =
s->cone_str,
363 .num_hooks =
s->num_hooks,
365 .skip_anti_aliasing =
s->skip_aa,
366 .polar_cutoff =
s->polar_cutoff,
367 .disable_linear_scaling =
s->disable_linear,
368 .disable_builtin_scalers =
s->disable_builtin,
369 .force_icc_lut =
s->force_icc_lut,
370 .force_dither =
s->force_dither,
371 .disable_fbos =
s->disable_fbos,
377 pl_render_image(
s->renderer, &image, &target, ¶ms);
378 pl_unmap_avframe(
s->gpu, &image);
379 pl_unmap_avframe(
s->gpu, &target);
382 pl_gpu_flush(
s->gpu);
386 pl_unmap_avframe(
s->gpu, &image);
387 pl_unmap_avframe(
s->gpu, &target);
393 int err, changed_csp;
409 out->width = outlink->
w;
410 out->height = outlink->
h;
420 if (
s->colorspace >= 0)
421 out->colorspace =
s->colorspace;
422 if (
s->color_range >= 0)
423 out->color_range =
s->color_range;
424 if (
s->color_trc >= 0)
425 out->color_trc =
s->color_trc;
426 if (
s->color_primaries >= 0)
427 out->color_primaries =
s->color_primaries;
439 if (
s->apply_dovi || changed_csp) {
443 if (
s->apply_filmgrain)
467 int *out_w = &
s->vkctx.output_width;
468 int *out_h = &
s->vkctx.output_height;
474 s->force_original_aspect_ratio,
475 s->force_divisible_by);
478 if (
inlink->sample_aspect_ratio.num)
481 if (
s->normalize_sar) {
483 s->target_sar = scale_sar;
488 if (
inlink->sample_aspect_ratio.num)
492 if (
s->out_format_string) {
500 s->vkctx.output_format =
s->vkctx.input_format;
506 vkfc->
usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
514 #define OFFSET(x) offsetof(LibplaceboContext, x)
515 #define STATIC (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
516 #define DYNAMIC (STATIC | AV_OPT_FLAG_RUNTIME_PARAM)
522 {
"force_original_aspect_ratio",
"decrease or increase w/h if necessary to keep the original AR",
OFFSET(force_original_aspect_ratio),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2,
STATIC,
"force_oar" },
526 {
"force_divisible_by",
"enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used",
OFFSET(force_divisible_by),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 256,
STATIC },
528 {
"pad_crop_ratio",
"ratio between padding and cropping when normalizing SAR (0=pad, 1=crop)",
OFFSET(pad_crop_ratio),
AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, 1.0,
DYNAMIC },
555 {
"auto",
"keep the same color primaries", 0,
AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX,
STATIC,
"color_primaries"},
571 {
"auto",
"keep the same color transfer", 0,
AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX,
STATIC,
"color_trc"},
616 {
"relative",
"Relative colorimetric", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_RELATIVE_COLORIMETRIC}, 0, 0,
STATIC,
"intent" },
617 {
"absolute",
"Absolute colorimetric", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_ABSOLUTE_COLORIMETRIC}, 0, 0,
STATIC,
"intent" },
618 {
"saturation",
"Saturation mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_INTENT_SATURATION}, 0, 0,
STATIC,
"intent" },
619 {
"tonemapping",
"Tone-mapping algorithm",
OFFSET(tonemapping),
AV_OPT_TYPE_INT, {.i64 = PL_TONE_MAPPING_BT_2390}, 0, PL_TONE_MAPPING_ALGORITHM_COUNT - 1,
DYNAMIC,
"tonemap" },
621 {
"mobius",
"Mobius tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_MOBIUS}, 0, 0,
STATIC,
"tonemap" },
622 {
"reinhard",
"Reinhard tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_REINHARD}, 0, 0,
STATIC,
"tonemap" },
623 {
"hable",
"Hable/Filmic tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_HABLE}, 0, 0,
STATIC,
"tonemap" },
624 {
"gamma",
"Gamma tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_GAMMA}, 0, 0,
STATIC,
"tonemap" },
625 {
"linear",
"Linear tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_LINEAR}, 0, 0,
STATIC,
"tonemap" },
626 {
"bt.2390",
"ITU-R BT.2390 tone-mapping", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_TONE_MAPPING_BT_2390}, 0, 0,
STATIC,
"tonemap" },
627 {
"tonemapping_param",
"Tunable parameter for some tone-mapping functions",
OFFSET(tonemapping_param),
AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 100.0, .flags =
DYNAMIC },
635 {
"dithering",
"Dither method to use",
OFFSET(dithering),
AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1,
DYNAMIC,
"dither" },
639 {
"ordered_fixed",
"Fixed function ordered", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_ORDERED_FIXED}, 0, 0,
STATIC,
"dither" },
658 {
"force_icc_lut",
"Force the use of a full ICC 3DLUT for color mapping",
OFFSET(force_icc_lut),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
DYNAMIC },
684 .
name =
"libplacebo",
693 .priv_class = &libplacebo_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
enum AVColorTransferCharacteristic color_trc
VkPhysicalDevice phys_dev
Physical device.
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
@ AVCOL_PRI_EBU3213
EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int log_cb(void *arg, enum rist_log_level log_level, const char *msg)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint8_t * data
The data buffer.
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
enum AVColorPrimaries color_primaries
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
enum AVColorSpace colorspace
YUV colorspace type.
This structure describes decoded (raw) audio or video data.
@ AVCOL_TRC_NB
Not part of ABI.
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to the instance-provided vkGetInstanceProcAddr loading function.
@ AVCOL_RANGE_JPEG
Full range content.
static void pl_av_log(void *log_ctx, enum pl_log_level level, const char *msg)
@ AVCOL_SPC_NB
Not part of ABI.
@ AV_FRAME_DATA_DOVI_RPU_BUFFER
Dolby Vision RPU raw data, suitable for passing to x265 or other libraries.
VkInstance inst
Vulkan instance.
#define AV_LOG_VERBOSE
Detailed information.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
static int process_frames(AVFilterContext *avctx, AVFrame *out, AVFrame *in)
void ff_vk_uninit(FFVulkanContext *s)
Frees the main Vulkan context.
const char * name
Filter name.
A link between two filters.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
AVFilter ff_vf_libplacebo
static int libplacebo_config_output(AVFilterLink *outlink)
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AV_OPT_TYPE_BINARY
offset must point to a pointer immediately followed by an int for the length
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
void * priv
private data for use by the filter
@ AVCOL_RANGE_NB
Not part of ABI.
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
static int find_scaler(AVFilterContext *avctx, const struct pl_filter_config **opt, const char *name)
static int filter_frame(AVFilterLink *link, AVFrame *in)
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
A filter pad used for either input or output.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AVCOL_PRI_NB
Not part of ABI.
int force_original_aspect_ratio
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
static int init_vulkan(AVFilterContext *avctx)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static const AVFilterPad libplacebo_inputs[]
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static void libplacebo_uninit(AVFilterContext *avctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
#define FILTER_INPUTS(array)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
int av_log_get_level(void)
Get the current log level.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int nb_enabled_dev_extensions
Rational number (pair of numerator and denominator).
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
AVFilterLink ** inputs
array of pointers to input links
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
int ff_vk_filter_config_output(AVFilterLink *outlink)
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
@ AVCOL_RANGE_UNSPECIFIED
static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AVCOL_PRI_FILM
colour filters using Illuminant C
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
AVFILTER_DEFINE_CLASS(libplacebo)
static const AVOption libplacebo_options[]
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_INFO
Standard information.
@ AVCOL_TRC_BT709
also ITU-R BT1361
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
static enum pl_log_level get_log_level(void)
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
#define i(width, name, range_min, range_max)
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
int w
agreed upon image width
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
const char * name
Pad name.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
This struct describes a set or pool of "hardware" frames (i.e.
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
int h
agreed upon image height
static const AVFilterPad libplacebo_outputs[]
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
const char *const * enabled_dev_extensions
Enabled device extensions.
int ff_vk_filter_config_input(AVFilterLink *inlink)
VkDevice act_dev
Active device.
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
#define FILTER_OUTPUTS(array)
static av_cold int uninit(AVCodecContext *avctx)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
VkPhysicalDeviceFeatures2 device_features
This structure should be set to the set of features that present and enabled during device creation.
static int libplacebo_init(AVFilterContext *avctx)
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
const struct pl_hook * hooks[2]
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]