21#include "config_components.h"
38#include <libplacebo/options.h>
39#include <libplacebo/renderer.h>
40#include <libplacebo/utils/libav.h>
41#include <libplacebo/utils/frame_queue.h>
42#include <libplacebo/vulkan.h>
45#include <libplacebo/compositor.h>
161 struct pl_custom_lut *
lut;
314 av_log(log_ctx, av_lev,
"%s\n", msg);
337 switch (gamut_mode) {
338 case GAMUT_MAP_CLIP: p->gamut_mapping = &pl_gamut_map_clip;
return;
353 const struct pl_filter_config **opt,
354 const char *
name,
int frame_mixing)
356 const struct pl_filter_preset *
preset, *presets_avail;
357 presets_avail = frame_mixing ? pl_frame_mixers : pl_scale_filters;
359 if (!strcmp(
name,
"help")) {
384 if ((
ret =
av_file_map(
s->lut_filename, &lutbuf, &lutbuf_size, 0,
s)) < 0) {
386 "The LUT file '%s' could not be read: %s\n",
391 s->lut = pl_lut_parse_cube(
s->log, lutbuf, lutbuf_size);
403 pl_options
opts =
s->opts;
404 int gamut_mode =
s->gamut_mode;
406 opts->deinterlace_params = *pl_deinterlace_params(
407 .
algo =
s->deinterlace,
408 .skip_spatial_check =
s->skip_spatial_check,
411 opts->deband_params = *pl_deband_params(
412 .iterations =
s->deband_iterations,
413 .threshold =
s->deband_threshold,
414 .radius =
s->deband_radius,
415 .grain =
s->deband_grain,
418 opts->sigmoid_params = pl_sigmoid_default_params;
420 opts->color_adjustment = (
struct pl_color_adjustment) {
421 .brightness =
s->brightness,
422 .contrast =
s->contrast,
423 .saturation =
s->saturation,
427 .temperature = (
s->temperature - 6500.0) / 3500.0,
430 opts->peak_detect_params = (
struct pl_peak_detect_params) {
431 PL_PEAK_DETECT_DEFAULTS
432 .smoothing_period =
s->smoothing,
433 .scene_threshold_low =
s->scene_low,
434 .scene_threshold_high =
s->scene_high,
435 .percentile =
s->percentile,
438 struct pl_tone_map_constants tone_constants =
s->tone_constants;
439 if (
s->tonemapping_param) {
440 switch (s->tonemapping) {
441 case TONE_MAP_ST2094_40:
442 case TONE_MAP_ST2094_10:
443 tone_constants.knee_adaptation = s->tonemapping_param;
445 case TONE_MAP_BT2390:
446 tone_constants.knee_offset = s->tonemapping_param;
449 case TONE_MAP_SPLINE:
450 tone_constants.spline_contrast = s->tonemapping_param;
452 case TONE_MAP_REINHARD:
453 tone_constants.reinhard_contrast = s->tonemapping_param;
455 case TONE_MAP_MOBIUS:
457 tone_constants.linear_knee = s->tonemapping_param;
459 case TONE_MAP_LINEAR:
460 tone_constants.exposure = s->tonemapping_param;
467 opts->color_map_params = (
struct pl_color_map_params) {
468 PL_COLOR_MAP_DEFAULTS
470 .tone_constants = tone_constants,
471 .inverse_tone_mapping =
s->inverse_tonemapping,
472 .lut_size =
s->tonemapping_lut_size,
473 .contrast_recovery =
s->contrast_recovery,
474 .contrast_smoothness =
s->contrast_smoothness,
479 opts->dither_params = *pl_dither_params(
480 .method =
s->dithering,
481 .lut_size =
s->dither_lut_size,
482 .temporal =
s->dither_temporal,
485 opts->cone_params = *pl_cone_params(
487 .strength =
s->cone_str,
490 opts->params = (
struct pl_render_params) {
492 .antiringing_strength =
s->antiringing,
493 .background_transparency = 1.0f - (
float)
s->fillcolor[3] / UINT8_MAX,
494 .background_color = {
495 (
float)
s->fillcolor[0] / UINT8_MAX,
496 (
float)
s->fillcolor[1] / UINT8_MAX,
497 (
float)
s->fillcolor[2] / UINT8_MAX,
499 .corner_rounding =
s->corner_rounding,
501 .deinterlace_params = &
opts->deinterlace_params,
502 .deband_params =
s->deband ? &
opts->deband_params :
NULL,
503 .sigmoid_params =
s->sigmoid ? &
opts->sigmoid_params :
NULL,
504 .color_adjustment = &
opts->color_adjustment,
505 .peak_detect_params =
s->peakdetect ? &
opts->peak_detect_params :
NULL,
506 .color_map_params = &
opts->color_map_params,
507 .dither_params =
s->dithering >= 0 ? &
opts->dither_params :
NULL,
508 .cone_params =
s->cones ? &
opts->cone_params :
NULL,
511 .num_hooks =
s->num_hooks,
513 .skip_anti_aliasing =
s->skip_aa,
514 .disable_linear_scaling =
s->disable_linear,
515 .disable_builtin_scalers =
s->disable_builtin,
516 .force_dither =
s->force_dither,
517 .disable_fbos =
s->disable_fbos,
525 if (!pl_options_set_str(
s->opts, e->key, e->value)) {
540 const struct pl_hook *hook;
542 hook = pl_mpv_user_shader_parse(
s->gpu, shader,
len);
548 s->hooks[
s->num_hooks++] = hook;
563 s->log = pl_log_create(PL_API_VER, pl_log_params(
572 if (
s->shader_cache &&
s->shader_cache[0]) {
573 s->cache = pl_cache_create(pl_cache_params(
575 .get = pl_cache_get_file,
576 .set = pl_cache_set_file,
577 .priv =
s->shader_cache,
583 if (
s->out_format_string) {
587 s->out_format_string);
602 for (
int i = 0;
i < nb_inputs;
i++) {
623 return avhwctx->
hwctx;
633 if (
s->normalize_sar &&
s->fit_mode !=
FIT_FILL) {
635 "a fit mode other than 'fill'\n");
643 s->opts = pl_options_alloc(
s->log);
668 if (strcmp(
s->fps_string,
"none") != 0)
674 if (!
s->inherit_device) {
685static void lock_queue(
void *priv, uint32_t qf, uint32_t qidx)
689#if FF_API_VULKAN_SYNC_QUEUES
691 hwctx->lock_queue(avhwctx, qf, qidx);
700#if FF_API_VULKAN_SYNC_QUEUES
702 hwctx->unlock_queue(avhwctx, qf, qidx);
714 input->
queue = pl_queue_create(
s->gpu);
715 input->
renderer = pl_renderer_create(
s->log,
s->gpu);
723 pl_renderer_destroy(&input->
renderer);
724 pl_queue_destroy(&input->
queue);
730 struct pl_vulkan_queue *pl_qf)
732 pl_qf->index = qf->
idx;
733 pl_qf->count = qf->
num;
753 struct pl_vulkan_import_params import_params = {
754 .instance = hwctx->
inst,
764 .queue_graphics = { VK_QUEUE_FAMILY_IGNORED },
765 .queue_compute = { VK_QUEUE_FAMILY_IGNORED },
766 .queue_transfer = { VK_QUEUE_FAMILY_IGNORED },
768 .max_api_version = VK_API_VERSION_1_3,
770 for (
int i = 0;
i < hwctx->
nb_qf;
i++) {
772 if (qf->
flags & VK_QUEUE_GRAPHICS_BIT)
774 if (qf->
flags & VK_QUEUE_COMPUTE_BIT)
776 if (qf->
flags & VK_QUEUE_TRANSFER_BIT)
781 s->vulkan = pl_vulkan_import(
s->log, &import_params);
782 s->have_hwdevice = 1;
784 s->vulkan = pl_vulkan_create(
s->log, pl_vulkan_params(
791 hwctx ?
"importing" :
"creating");
796 s->gpu =
s->vulkan->gpu;
797 pl_gpu_set_cache(
s->gpu,
s->cache);
816 if (
s->shader_bin_len)
819 if (
s->shader_path &&
s->shader_path[0]) {
828 s->inputs =
av_calloc(
s->nb_inputs,
sizeof(*
s->inputs));
831 for (
int i = 0;
i <
s->nb_inputs;
i++)
833 s->nb_active =
s->nb_inputs;
834 s->linear_rr = pl_renderer_create(
s->log,
s->gpu);
848 pl_tex_destroy(
s->gpu, &
s->tex[
i]);
849 for (
int i = 0;
i <
s->num_hooks;
i++)
850 pl_mpv_user_shader_destroy(&
s->hooks[
i]);
852 for (
int i = 0;
i <
s->nb_inputs;
i++)
857 pl_lut_free(&
s->lut);
858 pl_cache_destroy(&
s->cache);
859 pl_renderer_destroy(&
s->linear_rr);
860 pl_tex_destroy(
s->gpu, &
s->linear_tex);
861 pl_options_free(&
s->opts);
862 pl_vulkan_destroy(&
s->vulkan);
863 pl_log_destroy(&
s->log);
878 const char *
arg,
char *res,
int res_len,
892 for (
int i = 0;
i <
mix->num_frames;
i++) {
893 if (
i+1 ==
mix->num_frames ||
mix->timestamps[
i+1] > 0)
894 return pl_get_mapped_avframe(
mix->frames[
i]);
905 struct pl_frame *target,
double target_pts)
913 for (
int i = 0;
i < in->
mix.num_frames;
i++) {
916 struct pl_frame *image = (
struct pl_frame *) in->
mix.frames[
i];
917 const AVFrame *
src = pl_get_mapped_avframe(image);
952 image->crop.x1 = image->crop.x0 +
s->var_values[
VAR_CROP_W];
953 image->crop.y1 = image->crop.y0 +
s->var_values[
VAR_CROP_H];
955 const pl_rect2df crop_orig = image->crop;
956 pl_rotation rot_total = PL_ROTATION_360 + image->rotation - target->rotation;
957 if (rot_total % PL_ROTATION_180 == PL_ROTATION_90) {
960 FFSWAP(
float, image->crop.x0, image->crop.y0);
961 FFSWAP(
float, image->crop.x1, image->crop.y1);
968 target->crop.x1 = target->crop.x0 +
s->var_values[
VAR_POS_W];
969 target->crop.y1 = target->crop.y0 +
s->var_values[
VAR_POS_H];
974 if (rot_total % PL_ROTATION_180 == PL_ROTATION_90)
975 sar_in = 1.0 / sar_in;
977 pl_rect2df
fixed = crop_orig;
978 pl_rect2df_stretch(&
fixed, sar_in / sar_out, 1.0);
980 switch (
s->fit_mode) {
982 if (
s->normalize_sar)
983 pl_rect2df_aspect_copy(&target->crop, &
fixed,
s->pad_crop_ratio);
986 pl_rect2df_aspect_copy(&target->crop, &
fixed, 0.0);
989 pl_rect2df_aspect_copy(&target->crop, &
fixed, 1.0);
992 const float sx =
fabsf(pl_rect_w(
fixed)) / pl_rect_w(target->crop);
993 const float sy =
fabsf(pl_rect_h(
fixed)) / pl_rect_h(target->crop);
994 pl_rect2df_stretch(&target->crop, sx, sy);
998 pl_rect2df_aspect_fit(&target->crop, &
fixed, 0.0);
1010 ok = pl_map_avframe_ex(
s->gpu, target, pl_avframe_params(
1015 ok = pl_frame_recreate_from_avframe(
s->gpu, target,
s->tex,
out);
1026 pl_unmap_avframe(
s->gpu, target);
1027 }
else if (!pl_download_avframe(
s->gpu, target,
out)) {
1037 int err, changed = 0;
1052 out->width = outlink->
w;
1053 out->height = outlink->
h;
1060 if (
s->color_trc >= 0)
1061 out->color_trc =
s->color_trc;
1062 if (
s->color_primaries >= 0)
1063 out->color_primaries =
s->color_primaries;
1069 if (
out->width !=
ref->width ||
out->height !=
ref->height)
1071 if (
ref->color_trc !=
out->color_trc ||
ref->color_primaries !=
out->color_primaries)
1075 if (
s->apply_filmgrain)
1089 pl_options
opts =
s->opts;
1092 struct pl_frame target;
1098 int idx_start = 0, nb_visible = 0;
1099 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1101 struct pl_frame
dummy;
1102 if (in->
qstatus != PL_QUEUE_OK || !in->
mix.num_frames)
1104 const struct pl_frame *cur = pl_frame_mix_nearest(&in->
mix);
1113 const bool cropped = x0 > 0 || y0 > 0 || x1 < outlink->
w || y1 < outlink->
h;
1114 if (!cropped && cur->repr.alpha == PL_ALPHA_NONE) {
1142 struct pl_frame orig_target = target;
1143 bool use_linear_compositor =
false;
1144 if (
s->linear_tex && target.color.transfer != PL_COLOR_TRC_LINEAR &&
1145 !
s->disable_linear && nb_visible > 1) {
1146 target = (
struct pl_frame) {
1150 .component_mapping = {0, 1, 2, 3},
1151 .texture =
s->linear_tex,
1153 .repr = pl_color_repr_rgb,
1154 .color = orig_target.color,
1155 .rotation = orig_target.rotation,
1157 target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
1158 target.color.transfer = PL_COLOR_TRC_LINEAR;
1159 use_linear_compositor =
true;
1163 struct pl_render_params tmp_params =
opts->params;
1164 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1171 if (in->
qstatus != PL_QUEUE_OK || !in->
mix.num_frames ||
i < idx_start) {
1172 pl_renderer_flush_cache(in->
renderer);
1175 tmp_params.skip_caching_single_frame = high_fps;
1177 pl_render_image_mix(in->
renderer, &in->
mix, &target, &tmp_params);
1181 target.repr.alpha = PL_ALPHA_INDEPENDENT;
1182 tmp_params.blend_params = &pl_alpha_overlay;
1183 tmp_params.background = tmp_params.border = PL_CLEAR_SKIP;
1186 if (use_linear_compositor) {
1188 target.crop = orig_target.crop = (
struct pl_rect2df) {0};
1189 target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
1190 pl_render_image(
s->linear_rr, &target, &orig_target, &
opts->params);
1191 target = orig_target;
1194 pl_render_image(
s->linear_rr,
NULL, &target, &
opts->params);
1206 const struct pl_source_frame *
src,
1207 struct pl_frame *
out)
1211 bool ok = pl_map_avframe_ex(gpu,
out, pl_avframe_params(
1214 .map_dovi =
s->apply_dovi,
1217 out->lut_type =
s->lut_type;
1218 out->rotation +=
s->rotation;
1220 if (!
s->apply_filmgrain)
1221 out->film_grain.type = PL_FILM_GRAIN_NONE;
1228 const struct pl_source_frame *
src)
1230 pl_unmap_avframe(gpu,
frame);
1244 struct pl_source_frame
src = {
1247 .first_field = deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE,
1260 return src.first_field;
1281 if (
s->send_fields && field != PL_FIELD_NONE) {
1313 int ret, ok = 0, retry = 0;
1322 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1332 out_pts = INT64_MAX;
1333 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1337 }
else if (!in->
status) {
1348 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1353 pl_renderer_destroy(&in->
renderer);
1354 pl_queue_destroy(&in->
queue);
1361 .radius = pl_frame_mix_radius(&
s->opts->params),
1371 ok |= in->
mix.num_frames > 0;
1380 ok |=
s->fps.num &&
s->nb_active > 0;
1386 for (
int i = 0;
i <
s->nb_inputs;
i++)
1389 }
else if (
s->nb_active == 0) {
1391 int status =
s->inputs[0].status;
1392 int64_t status_pts =
s->inputs[0].status_pts;
1393 for (
int i = 1;
i <
s->nb_inputs;
i++) {
1433 if (
s->have_hwdevice) {
1444 if (!pl_test_pixfmt(
s->gpu,
pixfmt))
1457 if (!pl_test_pixfmt_caps(
s->gpu,
pixfmt, PL_FMT_CAP_RENDERABLE))
1465 if (!infmts || !outfmts) {
1470 for (
int i = 0;
i <
s->nb_inputs;
i++) {
1506 if (outfmts && !outfmts->refcount)
1526 "hardware frames context on the input.\n");
1545 s->vkctx.input_format = inlink->
format;
1556 if (
s->rotation % PL_ROTATION_180 == PL_ROTATION_90) {
1564 if (
s->inherit_device)
1590 s->vkctx.output_width = outlink->
w;
1591 s->vkctx.output_height = outlink->
h;
1594 s->vkctx.output_format =
s->vkctx.input_format;
1596 s->vkctx.output_format =
s->out_format;
1602 vkfc->
usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1618 &outlink->
w, &outlink->
h));
1620 s->reset_sar |=
s->normalize_sar ||
s->nb_inputs > 1;
1623 int force_oar =
s->force_original_aspect_ratio;
1633 force_oar,
s->force_divisible_by,
1634 s->reset_sar ? sar_in : 1.0));
1637 int w_adj =
s->reset_sar ? sar_in * inlink->
w : inlink->
w;
1638 outlink->
w =
FFMIN(outlink->
w, w_adj);
1639 outlink->
h =
FFMIN(outlink->
h, inlink->
h);
1642 if (
s->nb_inputs > 1 && !
s->disable_fbos) {
1644 const enum pl_fmt_caps caps = PL_FMT_CAP_BLENDABLE | PL_FMT_CAP_BLITTABLE;
1645 pl_fmt fmt = pl_find_fmt(
s->gpu, PL_FMT_FLOAT, 4, 16, 0, caps);
1648 ok = pl_tex_recreate(
s->gpu, &
s->linear_tex, pl_tex_params(
1655 .storable = fmt->caps & PL_FMT_CAP_STORABLE,
1661 "for compositing multiple inputs, falling back to non-linear "
1692 for (
int i = 1;
i <
s->nb_inputs;
i++) {
1700 if (
s->deinterlace &&
s->send_fields) {
1723#define OFFSET(x) offsetof(LibplaceboContext, x)
1724#define STATIC (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
1725#define DYNAMIC (STATIC | AV_OPT_FLAG_RUNTIME_PARAM)
1727#define OPTS_COMMON \
1728 { "format", "Output video format", OFFSET(out_format_string), AV_OPT_TYPE_STRING, .flags = STATIC }, \
1729 { "sar", "Output sample aspect ratio (0 for automatic)", OFFSET(out_sar), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, INT_MAX, STATIC }, \
1730 { "inherit_device", "Inherit the Vulkan device from the input's hardware frames context", \
1731 OFFSET(inherit_device), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, .flags = STATIC }, \
1732 { "shader_cache", "Set shader cache path", OFFSET(shader_cache), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = STATIC }, \
1733 { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, \
1734 { "apply_dolbyvision", "Apply Dolby Vision metadata", OFFSET(apply_dovi), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, \
1736 {"colorspace", "select colorspace", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_SPC_NB-1, STATIC, .unit = "colorspace"}, \
1737 {"auto", "use the negotiated colorspace", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1738 {"gbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_RGB}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1739 {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1740 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1741 {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT470BG}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1742 {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1743 {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1744 {"ycgco", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_YCGCO}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1745 {"bt2020nc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_NCL}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1746 {"bt2020c", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_CL}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1747 {"ictcp", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_ICTCP}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"}, \
1749 {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_RANGE_NB-1, STATIC, .unit = "range"}, \
1750 {"auto", "use the negotiated color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, STATIC, .unit = "range"}, \
1751 {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, STATIC, .unit = "range"}, \
1752 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, STATIC, .unit = "range"}, \
1753 {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"}, \
1754 {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"}, \
1755 {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"}, \
1756 {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"}, \
1757 {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"}, \
1758 {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"}, \
1760 {"color_primaries", "select color primaries", OFFSET(color_primaries), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_PRI_EXT_NB-1, DYNAMIC, .unit = "color_primaries"}, \
1761 {"auto", "keep the same color primaries", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1762 {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1763 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1764 {"bt470m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT470M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1765 {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT470BG}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1766 {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1767 {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1768 {"film", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_FILM}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1769 {"bt2020", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT2020}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1770 {"smpte428", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE428}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1771 {"smpte431", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1772 {"smpte432", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1773 {"jedec-p22", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_JEDEC_P22}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1774 {"ebu3213", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_EBU3213}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1775 {"vgamut", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_V_GAMUT}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"}, \
1777 {"color_trc", "select color transfer", OFFSET(color_trc), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_EXT_NB-1, DYNAMIC, .unit = "color_trc"}, \
1778 {"auto", "keep the same color transfer", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1779 {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1780 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1781 {"gamma22", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA22}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1782 {"bt470m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA22}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1783 {"gamma28", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA28}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1784 {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA28}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1785 {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1786 {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1787 {"linear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_LINEAR}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1788 {"iec61966-2-4", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_IEC61966_2_4}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1789 {"bt1361e", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT1361_ECG}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1790 {"iec61966-2-1", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_IEC61966_2_1}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1791 {"bt2020-10", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT2020_10}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1792 {"bt2020-12", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT2020_12}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1793 {"smpte2084", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE2084}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1794 {"arib-std-b67", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_ARIB_STD_B67}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1795 {"vlog", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_V_LOG}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"}, \
1797 {"chroma_location", "select chroma location", OFFSET(chroma_location), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCHROMA_LOC_NB-1, STATIC, .unit = "chroma_location"}, \
1798 {"auto", "use the negotiated chroma location", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, STATIC, .unit = "chroma_location"}, \
1799 {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, 0, 0, STATIC, .unit = "chroma_location"}, \
1800 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_UNSPECIFIED}, 0, 0, STATIC, .unit = "chroma_location"}, \
1801 {"left", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_LEFT}, 0, 0, STATIC, .unit = "chroma_location"}, \
1802 {"center", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_CENTER}, 0, 0, STATIC, .unit = "chroma_location"}, \
1803 {"topleft", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOPLEFT}, 0, 0, STATIC, .unit = "chroma_location"}, \
1804 {"top", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_TOP}, 0, 0, STATIC, .unit = "chroma_location"}, \
1805 {"bottomleft", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOMLEFT}, 0, 0, STATIC, .unit = "chroma_location"}, \
1806 {"bottom", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCHROMA_LOC_BOTTOM}, 0, 0, STATIC, .unit = "chroma_location"}, \
1808 {"alpha_mode", "select alpha moda", OFFSET(alpha_mode), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVALPHA_MODE_NB-1, STATIC, .unit = "alpha_mode"}, \
1809 {"auto", "use the negotiated alpha mode", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, STATIC, .unit = "alpha_mode"}, \
1810 {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED}, 0, 0, STATIC, .unit = "alpha_mode"}, \
1811 {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED}, 0, 0, STATIC, .unit = "alpha_mode"}, \
1812 {"premultiplied", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_PREMULTIPLIED}, 0, 0, STATIC, .unit = "alpha_mode"}, \
1813 {"straight", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_STRAIGHT}, 0, 0, STATIC, .unit = "alpha_mode"},
1828 {
"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,
SCALE_FORCE_OAR_NB-1,
STATIC, .unit =
"force_oar" },
1832 {
"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 },
1833 {
"reset_sar",
"force SAR normalization to 1:1 by adjusting pos_x/y/w/h",
OFFSET(reset_sar),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
STATIC },
1834 {
"normalize_sar",
"like reset_sar, but pad/crop instead of stretching the video",
OFFSET(normalize_sar),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
STATIC },
1835 {
"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 },
1837 {
"fill",
"Stretch content, ignoring aspect ratio", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_FILL }, 0, 0,
STATIC, .unit =
"fit_mode" },
1838 {
"contain",
"Stretch content, padding to preserve aspect", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_CONTAIN }, 0, 0,
STATIC, .unit =
"fit_mode" },
1839 {
"cover",
"Stretch content, cropping to preserve aspect", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_COVER }, 0, 0,
STATIC, .unit =
"fit_mode" },
1840 {
"none",
"Keep input unscaled, padding and cropping as needed", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_NONE }, 0, 0,
STATIC, .unit =
"fit_mode" },
1841 {
"place",
"Keep input unscaled, padding and cropping as needed", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_NONE }, 0, 0,
STATIC, .unit =
"fit_mode" },
1842 {
"scale_down",
"Downscale only if larger, padding to preserve aspect", 0,
AV_OPT_TYPE_CONST, {.i64 =
FIT_SCALE_DOWN }, 0, 0,
STATIC, .unit =
"fit_mode" },
1849 {
"lut_type",
"Application mode of the custom LUT",
OFFSET(lut_type),
AV_OPT_TYPE_INT, { .i64 = PL_LUT_UNKNOWN }, 0, PL_LUT_CONVERSION,
STATIC, .unit =
"lut_type" },
1855 {
"extra_opts",
"Pass extra libplacebo-specific options using a :-separated list of key=value pairs",
OFFSET(extra_opts),
AV_OPT_TYPE_DICT, .flags =
DYNAMIC },
1859 {
"rotate",
"rotate the input clockwise",
OFFSET(rotation),
AV_OPT_TYPE_INT, {.i64=PL_ROTATION_0}, PL_ROTATION_0, PL_ROTATION_360,
DYNAMIC, .unit =
"rotation"},
1872 {
"deinterlace",
"Deinterlacing mode",
OFFSET(deinterlace),
AV_OPT_TYPE_INT, {.i64 = PL_DEINTERLACE_WEAVE}, 0, PL_DEINTERLACE_ALGORITHM_COUNT - 1,
DYNAMIC, .unit =
"deinterlace" },
1873 {
"weave",
"Weave fields together (no-op)", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_WEAVE}, 0, 0,
STATIC, .unit =
"deinterlace" },
1874 {
"bob",
"Naive bob deinterlacing", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0,
STATIC, .unit =
"deinterlace" },
1875 {
"yadif",
"Yet another deinterlacing filter", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0,
STATIC, .unit =
"deinterlace" },
1876#if PL_API_VER >= 353
1877 {
"bwdif",
"Bob weaver deinterlacing filter", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BWDIF}, 0, 0,
STATIC, .unit =
"deinterlace" },
1925 {
"tonemapping_knee_adaptation",
"Scene-average knee point adaptation",
OFFSET(tone_constants.knee_adaptation),
AV_OPT_TYPE_FLOAT, {.dbl = 0.4}, 0.0, 1.0,
DYNAMIC },
1926 {
"tonemapping_knee_minimum",
"Minimum knee point in PQ space",
OFFSET(tone_constants.knee_minimum),
AV_OPT_TYPE_FLOAT, {.dbl = 0.1}, 0.0, 0.5,
DYNAMIC },
1927 {
"tonemapping_knee_maximum",
"Maximum knee point in PQ space",
OFFSET(tone_constants.knee_maximum),
AV_OPT_TYPE_FLOAT, {.dbl = 0.8}, 0.5, 1.0,
DYNAMIC },
1928 {
"tonemapping_knee_default",
"Fallback knee point without scene average metadata",
OFFSET(tone_constants.knee_default),
AV_OPT_TYPE_FLOAT, {.dbl = 0.4}, 0.0, 1.0,
DYNAMIC },
1929 {
"tonemapping_knee_offset",
"BT.2390 knee point offset",
OFFSET(tone_constants.knee_offset),
AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.5, 2.0,
DYNAMIC },
1932 {
"tonemapping_spline_contrast",
"Spline curve contrast",
OFFSET(tone_constants.spline_contrast),
AV_OPT_TYPE_FLOAT, {.dbl = 0.5}, 0.0, 1.5,
DYNAMIC },
1933 {
"tonemapping_reinhard_contrast",
"Reinhard contrast at the display peak",
OFFSET(tone_constants.reinhard_contrast),
AV_OPT_TYPE_FLOAT, {.dbl = 0.5}, 0.0, 1.0,
DYNAMIC },
1934 {
"tonemapping_linear_knee",
"Linear-light knee point for Mobius and gamma",
OFFSET(tone_constants.linear_knee),
AV_OPT_TYPE_FLOAT, {.dbl = 0.3}, 0.0, 1.0,
DYNAMIC },
1935 {
"tonemapping_exposure",
"Exposure for linear tone mapping",
OFFSET(tone_constants.exposure),
AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 10.0,
DYNAMIC },
1936 {
"inverse_tonemapping",
"Inverse tone mapping (range expansion)",
OFFSET(inverse_tonemapping),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
DYNAMIC },
1939 {
"contrast_smoothness",
"HDR contrast recovery smoothness",
OFFSET(contrast_smoothness),
AV_OPT_TYPE_FLOAT, {.dbl = 3.50}, 1.0, 32.0,
DYNAMIC },
1941 {
"dithering",
"Dither method to use",
OFFSET(dithering),
AV_OPT_TYPE_INT, {.i64 = PL_DITHER_BLUE_NOISE}, -1, PL_DITHER_METHOD_COUNT - 1,
DYNAMIC, .unit =
"dither" },
1943 {
"blue",
"Blue noise", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_BLUE_NOISE}, 0, 0,
STATIC, .unit =
"dither" },
1944 {
"ordered",
"Ordered LUT", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_ORDERED_LUT}, 0, 0,
STATIC, .unit =
"dither" },
1945 {
"ordered_fixed",
"Fixed function ordered", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_ORDERED_FIXED}, 0, 0,
STATIC, .unit =
"dither" },
1946 {
"white",
"White noise", 0,
AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_WHITE_NOISE}, 0, 0,
STATIC, .unit =
"dither" },
1979 .p.name =
"libplacebo",
1981 .p.priv_class = &libplacebo_class,
1993#if CONFIG_LIBPLACEBO_SCENE_FILTER
1998 pl_compositor
comp =
s->scene->comp;
1999 if (
comp->inputs[0]->renderer)
2002 if (!pl_compositor_init(
comp,
s->gpu))
2014 if (
s->inherit_device)
2017 RET(scene_setup_gpu(avctx));
2030 if (!
s->scene_json || !
s->w_expr || !
s->h_expr || !
s->fps_string) {
2039 s->scene = pl_scene_create_json(
s->log,
s->scene_json, strlen(
s->scene_json));
2045 comp =
s->scene->comp;
2046 s->nb_inputs =
comp->num_inputs;
2047 if (!
s->nb_inputs) {
2053 if (
s->colorspace < 0 &&
comp->repr.sys)
2054 s->colorspace = pl_system_to_av(
comp->repr.sys);
2055 if (
s->color_range < 0 &&
comp->repr.levels)
2056 s->color_range = pl_levels_to_av(
comp->repr.levels);
2057 if (
s->alpha_mode < 0 &&
comp->repr.alpha)
2058 s->alpha_mode = pl_alpha_to_av(
comp->repr.alpha);
2059 if (
s->chroma_location < 0 &&
comp->chroma_location)
2060 s->chroma_location = pl_chroma_to_av(
comp->chroma_location);
2061 if (
s->color_primaries < 0 &&
comp->color.primaries)
2062 s->color_primaries = pl_primaries_to_av(
comp->color.primaries);
2063 if (
s->color_trc < 0 &&
comp->color.transfer)
2064 s->color_trc = pl_transfer_to_av(
comp->color.transfer);
2068 if (!
s->inherit_device) {
2070 RET(scene_setup_gpu(avctx));
2082 pl_scene_destroy(&
s->scene);
2091 if (err < 0 || res < 1 || res > INT_MAX) {
2093 return err < 0 ? err :
AVERROR(EINVAL);
2107 RET(scene_eval_dim(avctx,
s->w_expr, &outlink->
w));
2108 RET(scene_eval_dim(avctx,
s->h_expr, &outlink->
h));
2125 pl_input input =
s->scene->comp->inputs[idx];
2126 const bool deinterlace = input->params && input->params->deinterlace_params;
2131 push_frame(
s, input->queue, inlink, in, deinterlace);
2137 pl_queue_set_status(input->queue, status ==
AVERROR_EOF ? PL_QUEUE_EOF : PL_QUEUE_ERR);
2138 input->user_data = (
void *) (intptr_t) status;
2145 const struct pl_queue_params *qparams,
2146 const struct pl_compositor_status *st)
2152 const AVFrame *
ref = st->base ? pl_get_mapped_avframe(st->base) :
NULL;
2153 struct pl_frame target;
2165 ok = pl_compositor_render(
s->scene->comp, &target, qparams,
NULL);
2184 pl_compositor
comp =
s->scene->comp;
2189 for (
int i = 0;
i <
s->nb_inputs;
i++) {
2190 if ((
ret = scene_handle_input(
ctx,
i)) < 0)
2198 const struct pl_queue_params qparams = *pl_queue_params(
2203 pl_scene_update(
s->scene, qparams.pts);
2205 struct pl_compositor_status st;
2206 st = pl_compositor_update(
comp, &qparams, pl_canvas_size(
2208 .height = outlink->
h,
2212 for (
int i = 0;
i <
s->nb_inputs;
i++) {
2214 switch (st.input_status[
i].status) {
2225 case PL_QUEUE_ERR: {
2227 const int status = (intptr_t)
comp->inputs[
i]->user_data;
2241 if (st.status == PL_QUEUE_EOF) {
2246 return scene_output_frame(
ctx, out_pts, &qparams, &st);
2249static const AVOption libplacebo_scene_options[] = {
2260static const AVFilterPad libplacebo_scene_outputs[] = {
2264 .config_props = &scene_config_output,
2269 .p.name =
"libplacebo_scene",
2270 .p.description =
NULL_IF_CONFIG_SMALL(
"Composite inputs according to a libplacebo scene graph"),
2271 .p.priv_class = &libplacebo_scene_class,
2274 .
init = &scene_init,
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static const char *const format[]
const FFFilter ff_vf_libplacebo_scene
const FFFilter ff_vf_libplacebo
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
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.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static IPT saturation(const CmsCtx *ctx, IPT ipt)
static __device__ float fabsf(float a)
int(* init)(AVBSFContext *ctx)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
reference-counted frame API
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
@ AV_SIDE_DATA_PROP_COLOR_DEPENDENT
Side data depends on the video color space.
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_log_get_level(void)
Get the current log level.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
Return the best rational so that a and b are multiple of it.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_UP
Round toward +infinity.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
@ AV_HWDEVICE_TYPE_VULKAN
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the optimal per-plane Vulkan format for a given sw_format, one for each plane.
enum AVPixelFormat pixfmt
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int mix(int c0, int c1)
#define fixed(width, name, value)
static void log_cb(cmsContext ctx, cmsUInt32Number error, const char *str)
static int get_log_level(int level)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FLAG_DYNAMIC_FRAME_PARAMS
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
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...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static const char *const var_names[]
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
@ AVCHROMA_LOC_UNSPECIFIED
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
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.
@ SCALE_FORCE_OAR_DISABLE
@ SCALE_FORCE_OAR_INCREASE
@ SCALE_FORCE_OAR_DECREASE
#define FF_ARRAY_ELEMS(a)
static int config_props(AVBitStreamFilterLink *link)
uint8_t * data
The data buffer.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
enum AVChromaLocation chroma_location
Agreed upon chroma sample location, for video with subsampled chroma.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
enum AVAlphaMode alpha_mode
alpha mode (for videos with an alpha channel)
AVFilterContext * dst
dest filter
int format
agreed upon media format
enum AVColorRange color_range
agreed upon YUV color range
A filter pad used for either input or output.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
enum AVChromaLocation chroma_location
void * opaque
Frame owner's private data.
int64_t duration
Duration of the frame, in the same units as pts.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes a set or pool of "hardware" frames (i.e.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Rational number (pair of numerator and denominator).
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkPhysicalDevice phys_dev
Physical device.
AVVulkanDeviceQueueFamily qf[64]
Queue families used.
const char *const * enabled_dev_extensions
Enabled device extensions.
VkDevice act_dev
Active device.
VkInstance inst
Vulkan instance.
VkPhysicalDeviceFeatures2 device_features
This structure should be set to the set of features that present and enabled during device creation.
int nb_enabled_dev_extensions
VkDeviceQueueCreateFlags queue_flags
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
struct pl_custom_lut * lut
double var_values[VAR_VARS_NB]
float contrast_smoothness
AVDictionary * extra_opts
enum AVPixelFormat out_format
AVRational fps
parsed FPS, or 0/0 for "none"
int force_original_aspect_ratio
struct pl_tone_map_constants tone_constants
const struct pl_hook * hooks[2]
static int ref[MAX_W *MAX_W]
AVThreadMessageQueue * queue
static float sigmoid(float x)
static int libplacebo_config_output(AVFilterLink *outlink)
static int update_settings(AVFilterContext *ctx)
static const AVVulkanDeviceContext * choose_default_device(const AVFilterContext *avctx)
static int find_scaler(AVFilterContext *avctx, const struct pl_filter_config **opt, const char *name, int frame_mixing)
static const AVOption libplacebo_options[]
static void pl_av_log(void *log_ctx, enum pl_log_level level, const char *msg)
static int libplacebo_setup_gpu(AVFilterContext *avctx)
static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
static int init_common(AVFilterContext *avctx)
static int map_output(LibplaceboContext *s, AVFrame *out, struct pl_frame *target)
static enum pl_field push_frame(LibplaceboContext *s, pl_queue queue, const AVFilterLink *inlink, AVFrame *in, bool deinterlace)
static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx)
static const AVFilterPad libplacebo_outputs[]
static void lock_queue(void *priv, uint32_t qf, uint32_t qidx)
static void libplacebo_uninit(AVFilterContext *avctx)
static int handle_input(AVFilterContext *ctx, LibplaceboInput *input)
static int output_frame(AVFilterContext *ctx, int64_t pts)
static void unlock_queue(void *priv, uint32_t qf, uint32_t qidx)
static void unmap_frame(pl_gpu gpu, struct pl_frame *frame, const struct pl_source_frame *src)
static int unmap_output(LibplaceboContext *s, struct pl_frame *target, AVFrame *out)
static void set_gamut_mode(struct pl_color_map_params *p, int gamut_mode)
static int libplacebo_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
static void drain_input_pts(LibplaceboInput *in, int64_t until)
static int libplacebo_init(AVFilterContext *avctx)
static int parse_custom_lut(AVFilterContext *avctx)
static int set_output_props(LibplaceboContext *s, const AVFilterLink *outlink, AVFrame *out, const AVFrame *ref, bool progressive)
static const AVFrame * ref_frame(const struct pl_frame_mix *mix)
static bool map_frame(pl_gpu gpu, pl_tex *tex, const struct pl_source_frame *src, struct pl_frame *out)
static void discard_frame(const struct pl_source_frame *src)
static int libplacebo_config_input(AVFilterLink *inlink)
static int inherit_device(AVFilterLink *inlink)
static AVRational max_q(AVRational a, AVRational b)
static int copy_pl_queue(const AVVulkanDeviceContext *hwctx, const AVVulkanDeviceQueueFamily *qf, struct pl_vulkan_queue *pl_qf)
static int input_init(AVFilterContext *avctx, LibplaceboInput *input, int idx)
static const struct pl_tone_map_function * get_tonemapping_func(int tm)
static int config_output_vulkan(AVFilterLink *outlink)
static int libplacebo_query_format(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static double q2d_fallback(AVRational q, const double def)
static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, struct pl_frame *target, double target_pts)
const struct pl_scene_t * pl_scene
static int append_inputs(AVFilterContext *avctx, int nb_inputs, int(*config_props)(AVFilterLink *link))
static int libplacebo_activate(AVFilterContext *ctx)
static int config_input_vulkan(AVFilterLink *inlink)
static enum pl_log_level get_log_level(void)
static void input_uninit(LibplaceboInput *input)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int ff_vk_filter_config_input(AVFilterLink *inlink)
int ff_vk_filter_config_output(AVFilterLink *outlink)