FFmpeg
vf_libplacebo.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <math.h>
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/eval.h"
23 #include "libavutil/fifo.h"
24 #include "libavutil/file.h"
25 #include "libavutil/frame.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "formats.h"
30 #include "filters.h"
31 #include "video.h"
32 #include "vulkan_filter.h"
33 #include "scale_eval.h"
34 
35 #include <libplacebo/renderer.h>
36 #include <libplacebo/utils/libav.h>
37 #include <libplacebo/utils/frame_queue.h>
38 #include <libplacebo/vulkan.h>
39 
40 /* Backwards compatibility with older libplacebo */
41 #if PL_API_VER < 276
42 static inline AVFrame *pl_get_mapped_avframe(const struct pl_frame *frame)
43 {
44  return frame->user_data;
45 }
46 #endif
47 
48 #if PL_API_VER >= 309
49 #include <libplacebo/options.h>
50 #else
51 typedef struct pl_options_t {
52  // Backwards compatibility shim of this struct
53  struct pl_render_params params;
54  struct pl_deinterlace_params deinterlace_params;
55  struct pl_deband_params deband_params;
56  struct pl_sigmoid_params sigmoid_params;
57  struct pl_color_adjustment color_adjustment;
58  struct pl_peak_detect_params peak_detect_params;
59  struct pl_color_map_params color_map_params;
60  struct pl_dither_params dither_params;
61  struct pl_cone_params cone_params;
62 } *pl_options;
63 
64 #define pl_options_alloc(log) av_mallocz(sizeof(struct pl_options_t))
65 #define pl_options_free(ptr) av_freep(ptr)
66 #endif
67 
68 enum {
82 };
83 
84 enum {
95 };
96 
97 static const char *const var_names[] = {
98  "in_idx", "idx",///< index of input
99  "in_w", "iw", ///< width of the input video frame
100  "in_h", "ih", ///< height of the input video frame
101  "out_w", "ow", ///< width of the output video frame
102  "out_h", "oh", ///< height of the output video frame
103  "crop_w", "cw", ///< evaluated input crop width
104  "crop_h", "ch", ///< evaluated input crop height
105  "pos_w", "pw", ///< evaluated output placement width
106  "pos_h", "ph", ///< evaluated output placement height
107  "a", ///< iw/ih
108  "sar", ///< input pixel aspect ratio
109  "dar", ///< output pixel aspect ratio
110  "hsub", ///< input horizontal subsampling factor
111  "vsub", ///< input vertical subsampling factor
112  "ohsub", ///< output horizontal subsampling factor
113  "ovsub", ///< output vertical subsampling factor
114  "in_t", "t", ///< input frame pts
115  "out_t", "ot", ///< output frame pts
116  "n", ///< number of frame
117  NULL,
118 };
119 
120 enum var_name {
141 };
142 
143 /* per-input dynamic filter state */
144 typedef struct LibplaceboInput {
145  int idx;
146  pl_renderer renderer;
147  pl_queue queue;
148  enum pl_queue_status qstatus;
149  struct pl_frame_mix mix; ///< temporary storage
150  AVFifo *out_pts; ///< timestamps of wanted output frames
152  int status;
154 
155 enum fit_mode {
162 };
163 
164 enum fit_sense {
168 };
169 
170 typedef struct LibplaceboContext {
171  /* lavfi vulkan*/
173 
174  /* libplacebo */
175  pl_log log;
176  pl_vulkan vulkan;
177  pl_gpu gpu;
178  pl_tex tex[4];
179  struct pl_custom_lut *lut;
180 
181  /* dedicated renderer for linear output composition */
182  pl_renderer linear_rr;
183  pl_tex linear_tex;
184 
185  /* input state */
189 
190  /* settings */
193  uint8_t fillcolor[4];
195  char *w_expr;
196  char *h_expr;
197  char *fps_string;
198  AVRational fps; ///< parsed FPS, or 0/0 for "none"
203  // Parsed expressions for input/output crop
209  enum pl_lut_type lut_type;
214  int fit_mode;
222  int rotation;
225 
226 #if PL_API_VER >= 351
227  pl_cache cache;
228  char *shader_cache;
229 #endif
230 
232 
233  /* pl_render_params */
234  pl_options opts;
235  char *upscaler;
236  char *downscaler;
237  char *frame_mixer;
238  float antiringing;
239  int sigmoid;
240  int skip_aa;
245 
246  /* pl_deinterlace_params */
250 
251  /* pl_deband_params */
252  int deband;
257 
258  /* pl_color_adjustment */
259  float brightness;
260  float contrast;
261  float saturation;
262  float hue;
263  float gamma;
264 
265  /* pl_peak_detect_params */
267  float smoothing;
268  float scene_low;
269  float scene_high;
270  float percentile;
271 
272  /* pl_color_map_params */
280 
281  /* pl_dither_params */
285 
286  /* pl_cone_params */
287  int cones;
288  float cone_str;
289 
290  /* custom shaders */
291  char *shader_path;
292  void *shader_bin;
294  const struct pl_hook *hooks[2];
297 
298 static inline enum pl_log_level get_log_level(void)
299 {
300  int av_lev = av_log_get_level();
301  return av_lev >= AV_LOG_TRACE ? PL_LOG_TRACE :
302  av_lev >= AV_LOG_DEBUG ? PL_LOG_DEBUG :
303  av_lev >= AV_LOG_VERBOSE ? PL_LOG_INFO :
304  av_lev >= AV_LOG_WARNING ? PL_LOG_WARN :
305  av_lev >= AV_LOG_ERROR ? PL_LOG_ERR :
306  av_lev >= AV_LOG_FATAL ? PL_LOG_FATAL :
307  PL_LOG_NONE;
308 }
309 
310 static void pl_av_log(void *log_ctx, enum pl_log_level level, const char *msg)
311 {
312  int av_lev;
313 
314  switch (level) {
315  case PL_LOG_FATAL: av_lev = AV_LOG_FATAL; break;
316  case PL_LOG_ERR: av_lev = AV_LOG_ERROR; break;
317  case PL_LOG_WARN: av_lev = AV_LOG_WARNING; break;
318  case PL_LOG_INFO: av_lev = AV_LOG_VERBOSE; break;
319  case PL_LOG_DEBUG: av_lev = AV_LOG_DEBUG; break;
320  case PL_LOG_TRACE: av_lev = AV_LOG_TRACE; break;
321  default: return;
322  }
323 
324  av_log(log_ctx, av_lev, "%s\n", msg);
325 }
326 
327 static const struct pl_tone_map_function *get_tonemapping_func(int tm) {
328  switch (tm) {
329  case TONE_MAP_AUTO: return &pl_tone_map_auto;
330  case TONE_MAP_CLIP: return &pl_tone_map_clip;
331 #if PL_API_VER >= 246
332  case TONE_MAP_ST2094_40: return &pl_tone_map_st2094_40;
333  case TONE_MAP_ST2094_10: return &pl_tone_map_st2094_10;
334 #endif
335  case TONE_MAP_BT2390: return &pl_tone_map_bt2390;
336  case TONE_MAP_BT2446A: return &pl_tone_map_bt2446a;
337  case TONE_MAP_SPLINE: return &pl_tone_map_spline;
338  case TONE_MAP_REINHARD: return &pl_tone_map_reinhard;
339  case TONE_MAP_MOBIUS: return &pl_tone_map_mobius;
340  case TONE_MAP_HABLE: return &pl_tone_map_hable;
341  case TONE_MAP_GAMMA: return &pl_tone_map_gamma;
342  case TONE_MAP_LINEAR: return &pl_tone_map_linear;
343  default: av_assert0(0);
344  }
345 }
346 
347 static void set_gamut_mode(struct pl_color_map_params *p, int gamut_mode)
348 {
349  switch (gamut_mode) {
350 #if PL_API_VER >= 269
351  case GAMUT_MAP_CLIP: p->gamut_mapping = &pl_gamut_map_clip; return;
352  case GAMUT_MAP_PERCEPTUAL: p->gamut_mapping = &pl_gamut_map_perceptual; return;
353  case GAMUT_MAP_RELATIVE: p->gamut_mapping = &pl_gamut_map_relative; return;
354  case GAMUT_MAP_SATURATION: p->gamut_mapping = &pl_gamut_map_saturation; return;
355  case GAMUT_MAP_ABSOLUTE: p->gamut_mapping = &pl_gamut_map_absolute; return;
356  case GAMUT_MAP_DESATURATE: p->gamut_mapping = &pl_gamut_map_desaturate; return;
357  case GAMUT_MAP_DARKEN: p->gamut_mapping = &pl_gamut_map_darken; return;
358  case GAMUT_MAP_HIGHLIGHT: p->gamut_mapping = &pl_gamut_map_highlight; return;
359  case GAMUT_MAP_LINEAR: p->gamut_mapping = &pl_gamut_map_linear; return;
360 #else
361  case GAMUT_MAP_RELATIVE: p->intent = PL_INTENT_RELATIVE_COLORIMETRIC; return;
362  case GAMUT_MAP_SATURATION: p->intent = PL_INTENT_SATURATION; return;
363  case GAMUT_MAP_ABSOLUTE: p->intent = PL_INTENT_ABSOLUTE_COLORIMETRIC; return;
364  case GAMUT_MAP_DESATURATE: p->gamut_mode = PL_GAMUT_DESATURATE; return;
365  case GAMUT_MAP_DARKEN: p->gamut_mode = PL_GAMUT_DARKEN; return;
366  case GAMUT_MAP_HIGHLIGHT: p->gamut_mode = PL_GAMUT_WARN; return;
367  /* Use defaults for all other cases */
368  default: return;
369 #endif
370  }
371 
372  av_assert0(0);
373 };
374 
375 static int find_scaler(AVFilterContext *avctx,
376  const struct pl_filter_config **opt,
377  const char *name, int frame_mixing)
378 {
379  const struct pl_filter_preset *preset, *presets_avail;
380  presets_avail = frame_mixing ? pl_frame_mixers : pl_scale_filters;
381 
382  if (!strcmp(name, "help")) {
383  av_log(avctx, AV_LOG_INFO, "Available scaler presets:\n");
384  for (preset = presets_avail; preset->name; preset++)
385  av_log(avctx, AV_LOG_INFO, " %s\n", preset->name);
386  return AVERROR_EXIT;
387  }
388 
389  for (preset = presets_avail; preset->name; preset++) {
390  if (!strcmp(name, preset->name)) {
391  *opt = preset->filter;
392  return 0;
393  }
394  }
395 
396  av_log(avctx, AV_LOG_ERROR, "No such scaler preset '%s'.\n", name);
397  return AVERROR(EINVAL);
398 }
399 
401 {
402  LibplaceboContext *s = avctx->priv;
403  int ret;
404  uint8_t *lutbuf;
405  size_t lutbuf_size;
406 
407  if ((ret = av_file_map(s->lut_filename, &lutbuf, &lutbuf_size, 0, s)) < 0) {
408  av_log(avctx, AV_LOG_ERROR,
409  "The LUT file '%s' could not be read: %s\n",
410  s->lut_filename, av_err2str(ret));
411  return ret;
412  }
413 
414  s->lut = pl_lut_parse_cube(s->log, lutbuf, lutbuf_size);
415  av_file_unmap(lutbuf, lutbuf_size);
416  if (!s->lut)
417  return AVERROR(EINVAL);
418  return 0;
419 }
420 
422 {
423  int err = 0;
424  LibplaceboContext *s = ctx->priv;
425  AVDictionaryEntry *e = NULL;
426  pl_options opts = s->opts;
427  int gamut_mode = s->gamut_mode;
428 
429  opts->deinterlace_params = *pl_deinterlace_params(
430  .algo = s->deinterlace,
431  .skip_spatial_check = s->skip_spatial_check,
432  );
433 
434  opts->deband_params = *pl_deband_params(
435  .iterations = s->deband_iterations,
436  .threshold = s->deband_threshold,
437  .radius = s->deband_radius,
438  .grain = s->deband_grain,
439  );
440 
441  opts->sigmoid_params = pl_sigmoid_default_params;
442 
443  opts->color_adjustment = (struct pl_color_adjustment) {
444  .brightness = s->brightness,
445  .contrast = s->contrast,
446  .saturation = s->saturation,
447  .hue = s->hue,
448  .gamma = s->gamma,
449  };
450 
451  opts->peak_detect_params = *pl_peak_detect_params(
452  .smoothing_period = s->smoothing,
453  .scene_threshold_low = s->scene_low,
454  .scene_threshold_high = s->scene_high,
455 #if PL_API_VER >= 263
456  .percentile = s->percentile,
457 #endif
458  );
459 
460  opts->color_map_params = *pl_color_map_params(
461  .tone_mapping_function = get_tonemapping_func(s->tonemapping),
462  .tone_mapping_param = s->tonemapping_param,
463  .inverse_tone_mapping = s->inverse_tonemapping,
464  .lut_size = s->tonemapping_lut_size,
465 #if PL_API_VER >= 285
466  .contrast_recovery = s->contrast_recovery,
467  .contrast_smoothness = s->contrast_smoothness,
468 #endif
469  );
470 
471  set_gamut_mode(&opts->color_map_params, gamut_mode);
472 
473  opts->dither_params = *pl_dither_params(
474  .method = s->dithering,
475  .lut_size = s->dither_lut_size,
476  .temporal = s->dither_temporal,
477  );
478 
479  opts->cone_params = *pl_cone_params(
480  .cones = s->cones,
481  .strength = s->cone_str,
482  );
483 
484  opts->params = *pl_render_params(
485  .antiringing_strength = s->antiringing,
486  .background_transparency = 1.0f - (float) s->fillcolor[3] / UINT8_MAX,
487  .background_color = {
488  (float) s->fillcolor[0] / UINT8_MAX,
489  (float) s->fillcolor[1] / UINT8_MAX,
490  (float) s->fillcolor[2] / UINT8_MAX,
491  },
492 #if PL_API_VER >= 277
493  .corner_rounding = s->corner_rounding,
494 #endif
495 
496  .deinterlace_params = &opts->deinterlace_params,
497  .deband_params = s->deband ? &opts->deband_params : NULL,
498  .sigmoid_params = s->sigmoid ? &opts->sigmoid_params : NULL,
499  .color_adjustment = &opts->color_adjustment,
500  .peak_detect_params = s->peakdetect ? &opts->peak_detect_params : NULL,
501  .color_map_params = &opts->color_map_params,
502  .dither_params = s->dithering >= 0 ? &opts->dither_params : NULL,
503  .cone_params = s->cones ? &opts->cone_params : NULL,
504 
505  .hooks = s->hooks,
506  .num_hooks = s->num_hooks,
507 
508  .skip_anti_aliasing = s->skip_aa,
509  .disable_linear_scaling = s->disable_linear,
510  .disable_builtin_scalers = s->disable_builtin,
511  .force_dither = s->force_dither,
512  .disable_fbos = s->disable_fbos,
513  );
514 
515  RET(find_scaler(ctx, &opts->params.upscaler, s->upscaler, 0));
516  RET(find_scaler(ctx, &opts->params.downscaler, s->downscaler, 0));
517  RET(find_scaler(ctx, &opts->params.frame_mixer, s->frame_mixer, 1));
518 
519 #if PL_API_VER >= 309
520  while ((e = av_dict_get(s->extra_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
521  if (!pl_options_set_str(s->opts, e->key, e->value)) {
522  err = AVERROR(EINVAL);
523  goto fail;
524  }
525  }
526 #else
527  (void) e;
528  if (av_dict_count(s->extra_opts) > 0)
529  av_log(avctx, AV_LOG_WARNING, "extra_opts requires libplacebo >= 6.309!\n");
530 #endif
531 
532  return 0;
533 
534 fail:
535  return err;
536 }
537 
538 static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
539 {
540  LibplaceboContext *s = avctx->priv;
541  const struct pl_hook *hook;
542 
543  hook = pl_mpv_user_shader_parse(s->gpu, shader, len);
544  if (!hook) {
545  av_log(avctx, AV_LOG_ERROR, "Failed parsing custom shader!\n");
546  return AVERROR(EINVAL);
547  }
548 
549  s->hooks[s->num_hooks++] = hook;
550  return update_settings(avctx);
551 }
552 
553 static void libplacebo_uninit(AVFilterContext *avctx);
555 static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx);
556 
558 {
559  int err = 0;
560  LibplaceboContext *s = avctx->priv;
561  const AVVulkanDeviceContext *vkhwctx = NULL;
562 
563  if (s->normalize_sar && s->fit_mode != FIT_FILL) {
564  av_log(avctx, AV_LOG_WARNING, "normalize_sar has no effect when using "
565  "a fit mode other than 'fill'\n");
566  }
567 
568  /* Create libplacebo log context */
569  s->log = pl_log_create(PL_API_VER, pl_log_params(
570  .log_level = get_log_level(),
571  .log_cb = pl_av_log,
572  .log_priv = s,
573  ));
574 
575  if (!s->log)
576  return AVERROR(ENOMEM);
577 
578  s->opts = pl_options_alloc(s->log);
579  if (!s->opts) {
580  libplacebo_uninit(avctx);
581  return AVERROR(ENOMEM);
582  }
583 
584 #if PL_API_VER >= 351
585  if (s->shader_cache && s->shader_cache[0]) {
586  s->cache = pl_cache_create(pl_cache_params(
587  .log = s->log,
588  .get = pl_cache_get_file,
589  .set = pl_cache_set_file,
590  .priv = s->shader_cache,
591  ));
592  if (!s->cache) {
593  libplacebo_uninit(avctx);
594  return AVERROR(ENOMEM);
595  }
596  }
597 #endif
598 
599  if (s->out_format_string) {
600  s->out_format = av_get_pix_fmt(s->out_format_string);
601  if (s->out_format == AV_PIX_FMT_NONE) {
602  av_log(avctx, AV_LOG_ERROR, "Invalid output format: %s\n",
603  s->out_format_string);
604  libplacebo_uninit(avctx);
605  return AVERROR(EINVAL);
606  }
607  } else {
608  s->out_format = AV_PIX_FMT_NONE;
609  }
610 
611  for (int i = 0; i < s->nb_inputs; i++) {
612  AVFilterPad pad = {
613  .name = av_asprintf("input%d", i),
614  .type = AVMEDIA_TYPE_VIDEO,
615  .config_props = &libplacebo_config_input,
616  };
617  if (!pad.name)
618  return AVERROR(ENOMEM);
619  RET(ff_append_inpad_free_name(avctx, &pad));
620  }
621 
622  RET(update_settings(avctx));
623  RET(av_expr_parse(&s->crop_x_pexpr, s->crop_x_expr, var_names,
624  NULL, NULL, NULL, NULL, 0, s));
625  RET(av_expr_parse(&s->crop_y_pexpr, s->crop_y_expr, var_names,
626  NULL, NULL, NULL, NULL, 0, s));
627  RET(av_expr_parse(&s->crop_w_pexpr, s->crop_w_expr, var_names,
628  NULL, NULL, NULL, NULL, 0, s));
629  RET(av_expr_parse(&s->crop_h_pexpr, s->crop_h_expr, var_names,
630  NULL, NULL, NULL, NULL, 0, s));
631  RET(av_expr_parse(&s->pos_x_pexpr, s->pos_x_expr, var_names,
632  NULL, NULL, NULL, NULL, 0, s));
633  RET(av_expr_parse(&s->pos_y_pexpr, s->pos_y_expr, var_names,
634  NULL, NULL, NULL, NULL, 0, s));
635  RET(av_expr_parse(&s->pos_w_pexpr, s->pos_w_expr, var_names,
636  NULL, NULL, NULL, NULL, 0, s));
637  RET(av_expr_parse(&s->pos_h_pexpr, s->pos_h_expr, var_names,
638  NULL, NULL, NULL, NULL, 0, s));
639 
640  if (strcmp(s->fps_string, "none") != 0)
641  RET(av_parse_video_rate(&s->fps, s->fps_string));
642 
643  if (avctx->hw_device_ctx) {
644  const AVHWDeviceContext *avhwctx = (void *) avctx->hw_device_ctx->data;
645  if (avhwctx->type == AV_HWDEVICE_TYPE_VULKAN)
646  vkhwctx = avhwctx->hwctx;
647  }
648 
649  RET(init_vulkan(avctx, vkhwctx));
650 
651  return 0;
652 
653 fail:
654  return err;
655 }
656 
657 #if PL_API_VER >= 278
658 static void lock_queue(void *priv, uint32_t qf, uint32_t qidx)
659 {
660  AVHWDeviceContext *avhwctx = priv;
661  const AVVulkanDeviceContext *hwctx = avhwctx->hwctx;
662  hwctx->lock_queue(avhwctx, qf, qidx);
663 }
664 
665 static void unlock_queue(void *priv, uint32_t qf, uint32_t qidx)
666 {
667  AVHWDeviceContext *avhwctx = priv;
668  const AVVulkanDeviceContext *hwctx = avhwctx->hwctx;
669  hwctx->unlock_queue(avhwctx, qf, qidx);
670 }
671 #endif
672 
673 static int input_init(AVFilterContext *avctx, LibplaceboInput *input, int idx)
674 {
675  LibplaceboContext *s = avctx->priv;
676 
677  input->out_pts = av_fifo_alloc2(1, sizeof(int64_t), AV_FIFO_FLAG_AUTO_GROW);
678  if (!input->out_pts)
679  return AVERROR(ENOMEM);
680  input->queue = pl_queue_create(s->gpu);
681  input->renderer = pl_renderer_create(s->log, s->gpu);
682  input->idx = idx;
683 
684  return 0;
685 }
686 
688 {
689  pl_renderer_destroy(&input->renderer);
690  pl_queue_destroy(&input->queue);
691  av_fifo_freep2(&input->out_pts);
692 }
693 
694 static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx)
695 {
696  int err = 0;
697  LibplaceboContext *s = avctx->priv;
698  uint8_t *buf = NULL;
699  size_t buf_len;
700 
701  if (hwctx) {
702 #if PL_API_VER >= 278
703  struct pl_vulkan_import_params import_params = {
704  .instance = hwctx->inst,
705  .get_proc_addr = hwctx->get_proc_addr,
706  .phys_device = hwctx->phys_dev,
707  .device = hwctx->act_dev,
708  .extensions = hwctx->enabled_dev_extensions,
709  .num_extensions = hwctx->nb_enabled_dev_extensions,
710  .features = &hwctx->device_features,
711  .lock_queue = lock_queue,
712  .unlock_queue = unlock_queue,
713  .queue_ctx = avctx->hw_device_ctx->data,
714  .queue_graphics = {
715  .index = VK_QUEUE_FAMILY_IGNORED,
716  .count = 0,
717  },
718  .queue_compute = {
719  .index = VK_QUEUE_FAMILY_IGNORED,
720  .count = 0,
721  },
722  .queue_transfer = {
723  .index = VK_QUEUE_FAMILY_IGNORED,
724  .count = 0,
725  },
726  /* This is the highest version created by hwcontext_vulkan.c */
727  .max_api_version = VK_API_VERSION_1_3,
728  };
729  for (int i = 0; i < hwctx->nb_qf; i++) {
730  const AVVulkanDeviceQueueFamily *qf = &hwctx->qf[i];
731 
732  if (qf->flags & VK_QUEUE_GRAPHICS_BIT) {
733  import_params.queue_graphics.index = qf->idx;
734  import_params.queue_graphics.count = qf->num;
735  }
736  if (qf->flags & VK_QUEUE_COMPUTE_BIT) {
737  import_params.queue_compute.index = qf->idx;
738  import_params.queue_compute.count = qf->num;
739  }
740  if (qf->flags & VK_QUEUE_TRANSFER_BIT) {
741  import_params.queue_transfer.index = qf->idx;
742  import_params.queue_transfer.count = qf->num;
743  }
744  }
745 
746  /* Import libavfilter vulkan context into libplacebo */
747  s->vulkan = pl_vulkan_import(s->log, &import_params);
748 #else
749  av_log(avctx, AV_LOG_ERROR, "libplacebo version %s too old to import "
750  "Vulkan device, remove it or upgrade libplacebo to >= 5.278\n",
751  PL_VERSION);
752  err = AVERROR_EXTERNAL;
753  goto fail;
754 #endif
755 
756  s->have_hwdevice = 1;
757  } else {
758  s->vulkan = pl_vulkan_create(s->log, pl_vulkan_params(
759  .queue_count = 0, /* enable all queues for parallelization */
760  ));
761  }
762 
763  if (!s->vulkan) {
764  av_log(avctx, AV_LOG_ERROR, "Failed %s Vulkan device!\n",
765  hwctx ? "importing" : "creating");
766  err = AVERROR_EXTERNAL;
767  goto fail;
768  }
769 
770  s->gpu = s->vulkan->gpu;
771 #if PL_API_VER >= 351
772  pl_gpu_set_cache(s->gpu, s->cache);
773 #endif
774 
775  /* Parse the user shaders, if requested */
776  if (s->shader_bin_len)
777  RET(parse_shader(avctx, s->shader_bin, s->shader_bin_len));
778 
779  if (s->shader_path && s->shader_path[0]) {
780  RET(av_file_map(s->shader_path, &buf, &buf_len, 0, s));
781  RET(parse_shader(avctx, buf, buf_len));
782  }
783 
784  if (s->lut_filename)
785  RET(parse_custom_lut(avctx));
786 
787  /* Initialize inputs */
788  s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
789  if (!s->inputs)
790  return AVERROR(ENOMEM);
791  for (int i = 0; i < s->nb_inputs; i++)
792  RET(input_init(avctx, &s->inputs[i], i));
793  s->nb_active = s->nb_inputs;
794  s->linear_rr = pl_renderer_create(s->log, s->gpu);
795 
796  /* fall through */
797 fail:
798  if (buf)
799  av_file_unmap(buf, buf_len);
800  return err;
801 }
802 
804 {
805  LibplaceboContext *s = avctx->priv;
806 
807  for (int i = 0; i < FF_ARRAY_ELEMS(s->tex); i++)
808  pl_tex_destroy(s->gpu, &s->tex[i]);
809  for (int i = 0; i < s->num_hooks; i++)
810  pl_mpv_user_shader_destroy(&s->hooks[i]);
811  if (s->inputs) {
812  for (int i = 0; i < s->nb_inputs; i++)
813  input_uninit(&s->inputs[i]);
814  av_freep(&s->inputs);
815  }
816 
817  pl_lut_free(&s->lut);
818 #if PL_API_VER >= 351
819  pl_cache_destroy(&s->cache);
820 #endif
821  pl_renderer_destroy(&s->linear_rr);
822  pl_tex_destroy(s->gpu, &s->linear_tex);
823  pl_options_free(&s->opts);
824  pl_vulkan_destroy(&s->vulkan);
825  pl_log_destroy(&s->log);
826  ff_vk_uninit(&s->vkctx);
827  s->gpu = NULL;
828 
829  av_expr_free(s->crop_x_pexpr);
830  av_expr_free(s->crop_y_pexpr);
831  av_expr_free(s->crop_w_pexpr);
832  av_expr_free(s->crop_h_pexpr);
833  av_expr_free(s->pos_x_pexpr);
834  av_expr_free(s->pos_y_pexpr);
835  av_expr_free(s->pos_w_pexpr);
836  av_expr_free(s->pos_h_pexpr);
837 }
838 
839 static int libplacebo_process_command(AVFilterContext *ctx, const char *cmd,
840  const char *arg, char *res, int res_len,
841  int flags)
842 {
843  int err = 0;
844  RET(ff_filter_process_command(ctx, cmd, arg, res, res_len, flags));
846  return 0;
847 
848 fail:
849  return err;
850 }
851 
852 static const AVFrame *ref_frame(const struct pl_frame_mix *mix)
853 {
854  for (int i = 0; i < mix->num_frames; i++) {
855  if (i+1 == mix->num_frames || mix->timestamps[i+1] > 0)
856  return pl_get_mapped_avframe(mix->frames[i]);
857  }
858  return NULL;
859 }
860 
862  struct pl_frame *target, double target_pts)
863 {
864  FilterLink *outl = ff_filter_link(ctx->outputs[0]);
865  LibplaceboContext *s = ctx->priv;
866  const AVFilterLink *outlink = ctx->outputs[0];
867  const AVFilterLink *inlink = ctx->inputs[in->idx];
868  const AVFrame *ref = ref_frame(&in->mix);
869 
870  for (int i = 0; i < in->mix.num_frames; i++) {
871  // Mutate the `pl_frame.crop` fields in-place. This is fine because we
872  // own the entire pl_queue, and hence, the pointed-at frames.
873  struct pl_frame *image = (struct pl_frame *) in->mix.frames[i];
874  const AVFrame *src = pl_get_mapped_avframe(image);
875  double image_pts = TS2T(src->pts, inlink->time_base);
876 
877  /* Update dynamic variables */
878  s->var_values[VAR_IN_IDX] = s->var_values[VAR_IDX] = in->idx;
879  s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = inlink->w;
880  s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = inlink->h;
881  s->var_values[VAR_A] = (double) inlink->w / inlink->h;
882  s->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
883  av_q2d(inlink->sample_aspect_ratio) : 1.0;
884  s->var_values[VAR_IN_T] = s->var_values[VAR_T] = image_pts;
885  s->var_values[VAR_OUT_T] = s->var_values[VAR_OT] = target_pts;
886  s->var_values[VAR_N] = outl->frame_count_out;
887 
888  /* Clear these explicitly to avoid leaking previous frames' state */
889  s->var_values[VAR_CROP_W] = s->var_values[VAR_CW] = NAN;
890  s->var_values[VAR_CROP_H] = s->var_values[VAR_CH] = NAN;
891  s->var_values[VAR_POS_W] = s->var_values[VAR_PW] = NAN;
892  s->var_values[VAR_POS_H] = s->var_values[VAR_PH] = NAN;
893 
894  /* Compute dimensions first and placement second */
895  s->var_values[VAR_CROP_W] = s->var_values[VAR_CW] =
896  av_expr_eval(s->crop_w_pexpr, s->var_values, NULL);
897  s->var_values[VAR_CROP_H] = s->var_values[VAR_CH] =
898  av_expr_eval(s->crop_h_pexpr, s->var_values, NULL);
899  s->var_values[VAR_CROP_W] = s->var_values[VAR_CW] =
900  av_expr_eval(s->crop_w_pexpr, s->var_values, NULL);
901  s->var_values[VAR_POS_W] = s->var_values[VAR_PW] =
902  av_expr_eval(s->pos_w_pexpr, s->var_values, NULL);
903  s->var_values[VAR_POS_H] = s->var_values[VAR_PH] =
904  av_expr_eval(s->pos_h_pexpr, s->var_values, NULL);
905  s->var_values[VAR_POS_W] = s->var_values[VAR_PW] =
906  av_expr_eval(s->pos_w_pexpr, s->var_values, NULL);
907 
908  image->crop.x0 = av_expr_eval(s->crop_x_pexpr, s->var_values, NULL);
909  image->crop.y0 = av_expr_eval(s->crop_y_pexpr, s->var_values, NULL);
910  image->crop.x1 = image->crop.x0 + s->var_values[VAR_CROP_W];
911  image->crop.y1 = image->crop.y0 + s->var_values[VAR_CROP_H];
912  image->rotation = s->rotation;
913  if (s->rotation % PL_ROTATION_180 == PL_ROTATION_90) {
914  /* Libplacebo expects the input crop relative to the actual frame
915  * dimensions, so un-transpose them here */
916  FFSWAP(float, image->crop.x0, image->crop.y0);
917  FFSWAP(float, image->crop.x1, image->crop.y1);
918  }
919 
920  if (src == ref) {
921  /* Only update the target crop once, for the 'reference' frame */
922  target->crop.x0 = av_expr_eval(s->pos_x_pexpr, s->var_values, NULL);
923  target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL);
924  target->crop.x1 = target->crop.x0 + s->var_values[VAR_POS_W];
925  target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H];
926 
927  /* Effective visual crop */
928  const float w_adj = av_q2d(inlink->sample_aspect_ratio) /
929  av_q2d(outlink->sample_aspect_ratio);
930 
931  pl_rect2df fixed = image->crop;
932  pl_rect2df_stretch(&fixed, w_adj, 1.0);
933 
934  switch (s->fit_mode) {
935  case FIT_FILL:
936  if (s->normalize_sar)
937  pl_rect2df_aspect_copy(&target->crop, &fixed, s->pad_crop_ratio);
938  break;
939  case FIT_CONTAIN:
940  pl_rect2df_aspect_copy(&target->crop, &fixed, 0.0);
941  break;
942  case FIT_COVER:
943  pl_rect2df_aspect_copy(&target->crop, &fixed, 1.0);
944  break;
945  case FIT_NONE: {
946  const float sx = fabsf(pl_rect_w(fixed)) / pl_rect_w(target->crop);
947  const float sy = fabsf(pl_rect_h(fixed)) / pl_rect_h(target->crop);
948  pl_rect2df_stretch(&target->crop, sx, sy);
949  break;
950  }
951  case FIT_SCALE_DOWN:
952  pl_rect2df_aspect_fit(&target->crop, &fixed, 0.0);
953  }
954  }
955  }
956 }
957 
958 /* Construct and emit an output frame for a given timestamp */
960 {
961  int err = 0, ok, changed = 0;
962  LibplaceboContext *s = ctx->priv;
963  pl_options opts = s->opts;
964  AVFilterLink *outlink = ctx->outputs[0];
965  const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format);
966  const double target_pts = TS2T(pts, outlink->time_base);
967  struct pl_frame target;
968  const AVFrame *ref = NULL;
969  AVFrame *out;
970 
971  /* Count the number of visible inputs, by excluding frames which are fully
972  * obscured or which have no frames in the mix */
973  int idx_start = 0, nb_visible = 0;
974  for (int i = 0; i < s->nb_inputs; i++) {
975  LibplaceboInput *in = &s->inputs[i];
976  struct pl_frame dummy;
977  if (in->qstatus != PL_QUEUE_OK || !in->mix.num_frames)
978  continue;
979  const struct pl_frame *cur = pl_frame_mix_nearest(&in->mix);
980  av_assert1(cur);
981  update_crops(ctx, in, &dummy, target_pts);
982  const int x0 = roundf(FFMIN(dummy.crop.x0, dummy.crop.x1)),
983  y0 = roundf(FFMIN(dummy.crop.y0, dummy.crop.y1)),
984  x1 = roundf(FFMAX(dummy.crop.x0, dummy.crop.x1)),
985  y1 = roundf(FFMAX(dummy.crop.y0, dummy.crop.y1));
986 
987  /* If an opaque frame covers entire the output, disregard all lower layers */
988  const bool cropped = x0 > 0 || y0 > 0 || x1 < outlink->w || y1 < outlink->h;
989  if (!cropped && cur->repr.alpha == PL_ALPHA_NONE) {
990  idx_start = i;
991  nb_visible = 0;
992  ref = NULL;
993  }
994  /* Use first visible input as overall reference */
995  if (!ref)
996  ref = ref_frame(&in->mix);
997  nb_visible++;
998  }
999 
1000  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
1001  if (!out)
1002  return AVERROR(ENOMEM);
1003 
1004  if (!ref)
1005  goto props_done;
1006 
1008  out->width = outlink->w;
1009  out->height = outlink->h;
1010  out->colorspace = outlink->colorspace;
1011  out->color_range = outlink->color_range;
1012  out->alpha_mode = outlink->alpha_mode;
1013  if (s->deinterlace)
1015 
1017  /* Output of dovi reshaping is always BT.2020+PQ, so infer the correct
1018  * output colorspace defaults */
1019  out->color_primaries = AVCOL_PRI_BT2020;
1020  out->color_trc = AVCOL_TRC_SMPTE2084;
1022  }
1023 
1024  if (s->color_trc >= 0)
1025  out->color_trc = s->color_trc;
1026  if (s->color_primaries >= 0)
1027  out->color_primaries = s->color_primaries;
1028 
1029  /* Strip side data if no longer relevant */
1030  if (out->width != ref->width || out->height != ref->height)
1032  if (ref->color_trc != out->color_trc || ref->color_primaries != out->color_primaries)
1034  av_frame_side_data_remove_by_props(&out->side_data, &out->nb_side_data, changed);
1035 
1036  if (s->apply_filmgrain)
1038 
1039  if (s->reset_sar) {
1040  out->sample_aspect_ratio = ref->sample_aspect_ratio;
1041  } else {
1042  const AVRational ar_ref = { ref->width, ref->height };
1043  const AVRational ar_out = { out->width, out->height };
1044  const AVRational stretch = av_div_q(ar_ref, ar_out);
1045  out->sample_aspect_ratio = av_mul_q(ref->sample_aspect_ratio, stretch);
1046  }
1047 
1048 props_done:
1049  out->pts = pts;
1050  if (s->fps.num)
1051  out->duration = 1;
1052 
1053  /* Map, render and unmap output frame */
1054  if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1055  ok = pl_map_avframe_ex(s->gpu, &target, pl_avframe_params(
1056  .frame = out,
1057  .map_dovi = false,
1058  ));
1059  } else {
1060  ok = pl_frame_recreate_from_avframe(s->gpu, &target, s->tex, out);
1061  }
1062  if (!ok) {
1063  err = AVERROR_EXTERNAL;
1064  goto fail;
1065  }
1066 
1067  struct pl_frame orig_target = target;
1068  bool use_linear_compositor = false;
1069  if (s->linear_tex && target.color.transfer != PL_COLOR_TRC_LINEAR &&
1070  !s->disable_linear && nb_visible > 1) {
1071  target = (struct pl_frame) {
1072  .num_planes = 1,
1073  .planes[0] = {
1074  .components = 4,
1075  .component_mapping = {0, 1, 2, 3},
1076  .texture = s->linear_tex,
1077  },
1078  .repr = pl_color_repr_rgb,
1079  .color = orig_target.color,
1080  .rotation = orig_target.rotation,
1081  };
1082  target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
1083  target.color.transfer = PL_COLOR_TRC_LINEAR;
1084  use_linear_compositor = true;
1085  }
1086 
1087  /* Draw first frame opaque, others with blending */
1088  struct pl_render_params tmp_params = opts->params;
1089  for (int i = 0; i < s->nb_inputs; i++) {
1090  LibplaceboInput *in = &s->inputs[i];
1091  FilterLink *il = ff_filter_link(ctx->inputs[i]);
1092  FilterLink *ol = ff_filter_link(outlink);
1093  int high_fps = av_cmp_q(il->frame_rate, ol->frame_rate) >= 0;
1094  if (in->qstatus != PL_QUEUE_OK || !in->mix.num_frames || i < idx_start) {
1095  pl_renderer_flush_cache(in->renderer);
1096  continue;
1097  }
1098  tmp_params.skip_caching_single_frame = high_fps;
1099  update_crops(ctx, in, &target, target_pts);
1100  pl_render_image_mix(in->renderer, &in->mix, &target, &tmp_params);
1101 
1102  /* Force straight output and set correct blend operator. This is
1103  * required to get correct blending onto YUV target buffers. */
1104  target.repr.alpha = PL_ALPHA_INDEPENDENT;
1105  tmp_params.blend_params = &pl_alpha_overlay;
1106 #if PL_API_VER >= 346
1107  tmp_params.background = tmp_params.border = PL_CLEAR_SKIP;
1108 #else
1109  tmp_params.skip_target_clearing = true;
1110 #endif
1111  }
1112 
1113  if (use_linear_compositor) {
1114  /* Blit the linear intermediate image to the output frame */
1115  target.crop = orig_target.crop = (struct pl_rect2df) {0};
1116  target.repr.alpha = PL_ALPHA_PREMULTIPLIED;
1117  pl_render_image(s->linear_rr, &target, &orig_target, &opts->params);
1118  target = orig_target;
1119  } else if (!ref) {
1120  /* Render an empty image to clear the frame to the desired fill color */
1121  pl_render_image(s->linear_rr, NULL, &target, &opts->params);
1122  }
1123 
1124  if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1125  pl_unmap_avframe(s->gpu, &target);
1126  } else if (!pl_download_avframe(s->gpu, &target, out)) {
1127  err = AVERROR_EXTERNAL;
1128  goto fail;
1129  }
1130  return ff_filter_frame(outlink, out);
1131 
1132 fail:
1133  av_frame_free(&out);
1134  return err;
1135 }
1136 
1137 static bool map_frame(pl_gpu gpu, pl_tex *tex,
1138  const struct pl_source_frame *src,
1139  struct pl_frame *out)
1140 {
1141  AVFrame *avframe = src->frame_data;
1142  LibplaceboContext *s = avframe->opaque;
1143  bool ok = pl_map_avframe_ex(gpu, out, pl_avframe_params(
1144  .frame = avframe,
1145  .tex = tex,
1146  .map_dovi = s->apply_dovi,
1147  ));
1148  out->lut = s->lut;
1149  out->lut_type = s->lut_type;
1150 
1151  if (!s->apply_filmgrain)
1152  out->film_grain.type = PL_FILM_GRAIN_NONE;
1153 
1154  av_frame_free(&avframe);
1155  return ok;
1156 }
1157 
1158 static void unmap_frame(pl_gpu gpu, struct pl_frame *frame,
1159  const struct pl_source_frame *src)
1160 {
1161  pl_unmap_avframe(gpu, frame);
1162 }
1163 
1164 static void discard_frame(const struct pl_source_frame *src)
1165 {
1166  AVFrame *avframe = src->frame_data;
1167  av_frame_free(&avframe);
1168 }
1169 
1171 {
1172  int ret, status;
1173  LibplaceboContext *s = ctx->priv;
1174  AVFilterLink *outlink = ctx->outputs[0];
1175  AVFilterLink *inlink = ctx->inputs[input->idx];
1176  AVFrame *in;
1177  int64_t pts;
1178 
1179  while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) {
1180  struct pl_source_frame src = {
1181  .pts = TS2T(in->pts, inlink->time_base),
1182  .duration = TS2T(in->duration, inlink->time_base),
1183  .first_field = s->deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE,
1184  .frame_data = in,
1185  .map = map_frame,
1186  .unmap = unmap_frame,
1187  .discard = discard_frame,
1188  };
1189 
1190  in->opaque = s;
1191  pl_queue_push(input->queue, &src);
1192 
1193  if (!s->fps.num) {
1194  /* Internally queue an output frame for the same PTS */
1195  pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base);
1196  av_fifo_write(input->out_pts, &pts, 1);
1197 
1198  if (s->send_fields && src.first_field != PL_FIELD_NONE) {
1199  /* Queue the second field for interlaced content */
1200  pts += av_rescale_q(in->duration, inlink->time_base, outlink->time_base) / 2;
1201  av_fifo_write(input->out_pts, &pts, 1);
1202  }
1203  }
1204  }
1205 
1206  if (ret < 0)
1207  return ret;
1208 
1209  if (!input->status && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1210  pts = av_rescale_q_rnd(pts, inlink->time_base, outlink->time_base,
1211  AV_ROUND_UP);
1212  pl_queue_push(input->queue, NULL); /* Signal EOF to pl_queue */
1213  input->status = status;
1214  input->status_pts = pts;
1215  s->nb_active--;
1216  }
1217 
1218  return 0;
1219 }
1220 
1221 static void drain_input_pts(LibplaceboInput *in, int64_t until)
1222 {
1223  int64_t pts;
1224  while (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0 && pts <= until)
1225  av_fifo_drain2(in->out_pts, 1);
1226 }
1227 
1229 {
1230  int ret, ok = 0, retry = 0;
1231  LibplaceboContext *s = ctx->priv;
1232  AVFilterLink *outlink = ctx->outputs[0];
1233  FilterLink *outl = ff_filter_link(outlink);
1234  int64_t pts, out_pts;
1235 
1237  pl_log_level_update(s->log, get_log_level());
1238 
1239  for (int i = 0; i < s->nb_inputs; i++) {
1240  if ((ret = handle_input(ctx, &s->inputs[i])) < 0)
1241  return ret;
1242  }
1243 
1244  if (ff_outlink_frame_wanted(outlink)) {
1245  if (s->fps.num) {
1246  out_pts = outl->frame_count_out;
1247  } else {
1248  /* Determine the PTS of the next frame from any active input */
1249  out_pts = INT64_MAX;
1250  for (int i = 0; i < s->nb_inputs; i++) {
1251  LibplaceboInput *in = &s->inputs[i];
1252  if (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0) {
1253  out_pts = FFMIN(out_pts, pts);
1254  } else if (!in->status) {
1255  ff_inlink_request_frame(ctx->inputs[i]);
1256  retry = true;
1257  }
1258  }
1259 
1260  if (retry) /* some inputs are incomplete */
1261  return 0;
1262  }
1263 
1264  /* Update all input queues to the chosen out_pts */
1265  for (int i = 0; i < s->nb_inputs; i++) {
1266  LibplaceboInput *in = &s->inputs[i];
1267  FilterLink *l = ff_filter_link(outlink);
1268  if (in->status && out_pts >= in->status_pts) {
1269  in->qstatus = PL_QUEUE_EOF;
1270  continue;
1271  }
1272 
1273  in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params(
1274  .pts = TS2T(out_pts, outlink->time_base),
1275  .radius = pl_frame_mix_radius(&s->opts->params),
1276  .vsync_duration = l->frame_rate.num ? av_q2d(av_inv_q(l->frame_rate)) : 0,
1277  ));
1278 
1279  switch (in->qstatus) {
1280  case PL_QUEUE_MORE:
1281  ff_inlink_request_frame(ctx->inputs[i]);
1282  retry = true;
1283  break;
1284  case PL_QUEUE_OK:
1285  ok |= in->mix.num_frames > 0;
1286  break;
1287  case PL_QUEUE_ERR:
1288  return AVERROR_EXTERNAL;
1289  }
1290  }
1291 
1292  /* In constant FPS mode, we can also output an empty frame if there is
1293  * a gap in the input timeline and we still have active streams */
1294  ok |= s->fps.num && s->nb_active > 0;
1295 
1296  if (retry) {
1297  return 0;
1298  } else if (ok) {
1299  /* Got any valid frame mixes, drain PTS queue and render output */
1300  for (int i = 0; i < s->nb_inputs; i++)
1301  drain_input_pts(&s->inputs[i], out_pts);
1302  return output_frame(ctx, out_pts);
1303  } else if (s->nb_active == 0) {
1304  /* Forward most recent status */
1305  int status = s->inputs[0].status;
1306  int64_t status_pts = s->inputs[0].status_pts;
1307  for (int i = 1; i < s->nb_inputs; i++) {
1308  const LibplaceboInput *in = &s->inputs[i];
1309  if (in->status_pts > status_pts) {
1310  status = s->inputs[i].status;
1311  status_pts = s->inputs[i].status_pts;
1312  }
1313  }
1314  ff_outlink_set_status(outlink, status, status_pts);
1315  return 0;
1316  }
1317 
1318  return AVERROR_BUG;
1319  }
1320 
1321  return FFERROR_NOT_READY;
1322 }
1323 
1325  AVFilterFormatsConfig **cfg_in,
1326  AVFilterFormatsConfig **cfg_out)
1327 {
1328  int err;
1329  const LibplaceboContext *s = ctx->priv;
1330  const AVPixFmtDescriptor *desc = NULL;
1331  AVFilterFormats *infmts = NULL, *outfmts = NULL;
1332 
1333  /* List AV_PIX_FMT_VULKAN first to prefer it when possible */
1334  if (s->have_hwdevice) {
1335  RET(ff_add_format(&infmts, AV_PIX_FMT_VULKAN));
1336  if (s->out_format == AV_PIX_FMT_NONE || av_vkfmt_from_pixfmt(s->out_format))
1337  RET(ff_add_format(&outfmts, AV_PIX_FMT_VULKAN));
1338  }
1339 
1340  while ((desc = av_pix_fmt_desc_next(desc))) {
1342  if (pixfmt == AV_PIX_FMT_VULKAN)
1343  continue; /* Handled above */
1344 
1345 #if PL_API_VER < 232
1346  // Older libplacebo can't handle >64-bit pixel formats, so safe-guard
1347  // this to prevent triggering an assertion
1348  if (av_get_bits_per_pixel(desc) > 64)
1349  continue;
1350 #endif
1351 
1352  if (!pl_test_pixfmt(s->gpu, pixfmt))
1353  continue;
1354 
1355  RET(ff_add_format(&infmts, pixfmt));
1356 
1357  /* Filter for supported output pixel formats */
1358  if (desc->flags & AV_PIX_FMT_FLAG_BE)
1359  continue; /* BE formats are not supported by pl_download_avframe */
1360 
1361  /* Mask based on user specified format */
1362  if (pixfmt != s->out_format && s->out_format != AV_PIX_FMT_NONE)
1363  continue;
1364 
1365 #if PL_API_VER >= 293
1366  if (!pl_test_pixfmt_caps(s->gpu, pixfmt, PL_FMT_CAP_RENDERABLE))
1367  continue;
1368 #endif
1369 
1370  RET(ff_add_format(&outfmts, pixfmt));
1371  }
1372 
1373  if (!infmts || !outfmts) {
1374  err = AVERROR(EINVAL);
1375  goto fail;
1376  }
1377 
1378  for (int i = 0; i < s->nb_inputs; i++) {
1379  if (i > 0) {
1380  /* Duplicate the format list for each subsequent input */
1381  infmts = NULL;
1382  for (int n = 0; n < cfg_in[0]->formats->nb_formats; n++)
1383  RET(ff_add_format(&infmts, cfg_in[0]->formats->formats[n]));
1384  }
1385  RET(ff_formats_ref(infmts, &cfg_in[i]->formats));
1386  RET(ff_formats_ref(ff_all_color_spaces(), &cfg_in[i]->color_spaces));
1387  RET(ff_formats_ref(ff_all_color_ranges(), &cfg_in[i]->color_ranges));
1388  RET(ff_formats_ref(ff_all_alpha_modes(), &cfg_in[i]->alpha_modes));
1389  }
1390 
1391  RET(ff_formats_ref(outfmts, &cfg_out[0]->formats));
1392 
1393  outfmts = s->colorspace > 0 ? ff_make_formats_list_singleton(s->colorspace)
1394  : ff_all_color_spaces();
1395  RET(ff_formats_ref(outfmts, &cfg_out[0]->color_spaces));
1396 
1397  outfmts = s->color_range > 0 ? ff_make_formats_list_singleton(s->color_range)
1398  : ff_all_color_ranges();
1399  RET(ff_formats_ref(outfmts, &cfg_out[0]->color_ranges));
1400 
1401  outfmts = s->alpha_mode > 0 ? ff_make_formats_list_singleton(s->alpha_mode)
1402  : ff_all_alpha_modes();
1403  RET(ff_formats_ref(outfmts, &cfg_out[0]->alpha_modes));
1404  return 0;
1405 
1406 fail:
1407  if (infmts && !infmts->refcount)
1408  ff_formats_unref(&infmts);
1409  if (outfmts && !outfmts->refcount)
1410  ff_formats_unref(&outfmts);
1411  return err;
1412 }
1413 
1415 {
1416  AVFilterContext *avctx = inlink->dst;
1417  LibplaceboContext *s = avctx->priv;
1418 
1419  if (s->rotation % PL_ROTATION_180 == PL_ROTATION_90) {
1420  /* Swap width and height for 90 degree rotations to make the size and
1421  * scaling calculations work out correctly */
1422  FFSWAP(int, inlink->w, inlink->h);
1423  if (inlink->sample_aspect_ratio.num)
1424  inlink->sample_aspect_ratio = av_inv_q(inlink->sample_aspect_ratio);
1425  }
1426 
1427  if (inlink->format == AV_PIX_FMT_VULKAN)
1429 
1430  /* Forward this to the vkctx for format selection */
1431  s->vkctx.input_format = inlink->format;
1432 
1433  return 0;
1434 }
1435 
1437 {
1438  return av_cmp_q(a, b) < 0 ? b : a;
1439 }
1440 
1442 {
1443  int err;
1444  FilterLink *l = ff_filter_link(outlink);
1445  AVFilterContext *avctx = outlink->src;
1446  LibplaceboContext *s = avctx->priv;
1447  AVFilterLink *inlink = outlink->src->inputs[0];
1448  FilterLink *ol = ff_filter_link(outlink);
1450  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
1451  AVHWFramesContext *hwfc;
1452  AVVulkanFramesContext *vkfc;
1453 
1454  /* Frame dimensions */
1455  RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
1456  &outlink->w, &outlink->h));
1457 
1458  s->reset_sar |= s->normalize_sar || s->nb_inputs > 1;
1459  double sar_in = inlink->sample_aspect_ratio.num ?
1460  av_q2d(inlink->sample_aspect_ratio) : 1.0;
1461 
1462  int force_oar = s->force_original_aspect_ratio;
1463  if (!force_oar && s->fit_sense == FIT_CONSTRAINT) {
1464  if (s->fit_mode == FIT_CONTAIN || s->fit_mode == FIT_SCALE_DOWN) {
1465  force_oar = SCALE_FORCE_OAR_DECREASE;
1466  } else if (s->fit_mode == FIT_COVER) {
1467  force_oar = SCALE_FORCE_OAR_INCREASE;
1468  }
1469  }
1470 
1471  ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h,
1472  force_oar, s->force_divisible_by,
1473  s->reset_sar ? sar_in : 1.0);
1474 
1475  if (s->fit_mode == FIT_SCALE_DOWN && s->fit_sense == FIT_CONSTRAINT) {
1476  int w_adj = s->reset_sar ? sar_in * inlink->w : inlink->w;
1477  outlink->w = FFMIN(outlink->w, w_adj);
1478  outlink->h = FFMIN(outlink->h, inlink->h);
1479  }
1480 
1481  if (s->nb_inputs > 1 && !s->disable_fbos) {
1482  /* Create a separate renderer and composition texture */
1483  const enum pl_fmt_caps caps = PL_FMT_CAP_BLENDABLE | PL_FMT_CAP_BLITTABLE;
1484  pl_fmt fmt = pl_find_fmt(s->gpu, PL_FMT_FLOAT, 4, 16, 0, caps);
1485  bool ok = !!fmt;
1486  if (ok) {
1487  ok = pl_tex_recreate(s->gpu, &s->linear_tex, pl_tex_params(
1488  .format = fmt,
1489  .w = outlink->w,
1490  .h = outlink->h,
1491  .blit_dst = true,
1492  .renderable = true,
1493  .sampleable = true,
1494  .storable = fmt->caps & PL_FMT_CAP_STORABLE,
1495  ));
1496  }
1497 
1498  if (!ok) {
1499  av_log(avctx, AV_LOG_WARNING, "Failed to create a linear texture "
1500  "for compositing multiple inputs, falling back to non-linear "
1501  "blending.\n");
1502  }
1503  }
1504 
1505  if (s->reset_sar) {
1506  /* SAR is normalized, or we have multiple inputs, set out to 1:1 */
1507  outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
1508  } else if (inlink->sample_aspect_ratio.num && s->fit_mode == FIT_FILL) {
1509  /* This is consistent with other scale_* filters, which only
1510  * set the outlink SAR to be equal to the scale SAR iff the input SAR
1511  * was set to something nonzero */
1512  const AVRational ar_in = { inlink->w, inlink->h };
1513  const AVRational ar_out = { outlink->w, outlink->h };
1514  const AVRational stretch = av_div_q(ar_in, ar_out);
1515  outlink->sample_aspect_ratio = av_mul_q(inlink->sample_aspect_ratio, stretch);
1516  } else {
1517  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
1518  }
1519 
1520  /* Frame rate */
1521  if (s->fps.num) {
1522  ol->frame_rate = s->fps;
1523  outlink->time_base = av_inv_q(s->fps);
1524  } else {
1525  FilterLink *il = ff_filter_link(avctx->inputs[0]);
1526  ol->frame_rate = il->frame_rate;
1527  outlink->time_base = avctx->inputs[0]->time_base;
1528  for (int i = 1; i < s->nb_inputs; i++) {
1529  il = ff_filter_link(avctx->inputs[i]);
1530  ol->frame_rate = max_q(ol->frame_rate, il->frame_rate);
1531  outlink->time_base = av_gcd_q(outlink->time_base,
1532  avctx->inputs[i]->time_base,
1534  }
1535 
1536  if (s->deinterlace && s->send_fields) {
1537  const AVRational q2 = { 2, 1 };
1538  ol->frame_rate = av_mul_q(ol->frame_rate, q2);
1539  /* Ensure output frame timestamps are divisible by two */
1540  outlink->time_base = av_div_q(outlink->time_base, q2);
1541  }
1542  }
1543 
1544  /* Static variables */
1545  s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = outlink->w;
1546  s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = outlink->h;
1547  s->var_values[VAR_DAR] = outlink->sample_aspect_ratio.num ?
1548  av_q2d(outlink->sample_aspect_ratio) : 1.0;
1549  s->var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
1550  s->var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
1551  s->var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
1552  s->var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
1553 
1554  if (outlink->format != AV_PIX_FMT_VULKAN)
1555  return 0;
1556 
1557  s->vkctx.output_width = outlink->w;
1558  s->vkctx.output_height = outlink->h;
1559  /* Default to reusing the input format */
1560  if (s->out_format == AV_PIX_FMT_NONE || s->out_format == AV_PIX_FMT_VULKAN) {
1561  s->vkctx.output_format = s->vkctx.input_format;
1562  } else {
1563  s->vkctx.output_format = s->out_format;
1564  }
1565  RET(ff_vk_filter_config_output(outlink));
1566  hwfc = (AVHWFramesContext *)l->hw_frames_ctx->data;
1567  vkfc = hwfc->hwctx;
1568  vkfc->usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1569 
1570  return 0;
1571 
1572 fail:
1573  return err;
1574 }
1575 
1576 #define OFFSET(x) offsetof(LibplaceboContext, x)
1577 #define STATIC (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
1578 #define DYNAMIC (STATIC | AV_OPT_FLAG_RUNTIME_PARAM)
1579 
1580 static const AVOption libplacebo_options[] = {
1581  { "inputs", "Number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, .flags = STATIC },
1582  { "w", "Output video frame width", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = STATIC },
1583  { "h", "Output video frame height", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = STATIC },
1584  { "fps", "Output video frame rate", OFFSET(fps_string), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = STATIC },
1585  { "crop_x", "Input video crop x", OFFSET(crop_x_expr), AV_OPT_TYPE_STRING, {.str = "(iw-cw)/2"}, .flags = DYNAMIC },
1586  { "crop_y", "Input video crop y", OFFSET(crop_y_expr), AV_OPT_TYPE_STRING, {.str = "(ih-ch)/2"}, .flags = DYNAMIC },
1587  { "crop_w", "Input video crop w", OFFSET(crop_w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = DYNAMIC },
1588  { "crop_h", "Input video crop h", OFFSET(crop_h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = DYNAMIC },
1589  { "pos_x", "Output video placement x", OFFSET(pos_x_expr), AV_OPT_TYPE_STRING, {.str = "(ow-pw)/2"}, .flags = DYNAMIC },
1590  { "pos_y", "Output video placement y", OFFSET(pos_y_expr), AV_OPT_TYPE_STRING, {.str = "(oh-ph)/2"}, .flags = DYNAMIC },
1591  { "pos_w", "Output video placement w", OFFSET(pos_w_expr), AV_OPT_TYPE_STRING, {.str = "ow"}, .flags = DYNAMIC },
1592  { "pos_h", "Output video placement h", OFFSET(pos_h_expr), AV_OPT_TYPE_STRING, {.str = "oh"}, .flags = DYNAMIC },
1593  { "format", "Output video format", OFFSET(out_format_string), AV_OPT_TYPE_STRING, .flags = STATIC },
1594  { "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" },
1595  { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_FORCE_OAR_DISABLE }, 0, 0, STATIC, .unit = "force_oar" },
1596  { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_FORCE_OAR_DECREASE }, 0, 0, STATIC, .unit = "force_oar" },
1597  { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = SCALE_FORCE_OAR_INCREASE }, 0, 0, STATIC, .unit = "force_oar" },
1598  { "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 },
1599  { "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 },
1600  { "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 },
1601  { "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 },
1602  { "fit_mode", "Content fit strategy for placing input layers in the output", OFFSET(fit_mode), AV_OPT_TYPE_INT, {.i64 = FIT_FILL }, 0, FIT_MODE_NB - 1, STATIC, .unit = "fit_mode" },
1603  { "fill", "Stretch content, ignoring aspect ratio", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_FILL }, 0, 0, STATIC, .unit = "fit_mode" },
1604  { "contain", "Stretch content, padding to preserve aspect", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_CONTAIN }, 0, 0, STATIC, .unit = "fit_mode" },
1605  { "cover", "Stretch content, cropping to preserve aspect", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_COVER }, 0, 0, STATIC, .unit = "fit_mode" },
1606  { "none", "Keep input unscaled, padding and cropping as needed", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_NONE }, 0, 0, STATIC, .unit = "fit_mode" },
1607  { "place", "Keep input unscaled, padding and cropping as needed", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_NONE }, 0, 0, STATIC, .unit = "fit_mode" },
1608  { "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" },
1609  { "fit_sense", "Output size strategy (for the base layer only)", OFFSET(fit_sense), AV_OPT_TYPE_INT, {.i64 = FIT_TARGET }, 0, FIT_SENSE_NB - 1, STATIC, .unit = "fit_sense" },
1610  { "target", "Computed resolution is the exact output size", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_TARGET }, 0, 0, STATIC, .unit = "fit_sense" },
1611  { "constraint", "Computed resolution constrains the output size", 0, AV_OPT_TYPE_CONST, {.i64 = FIT_CONSTRAINT }, 0, 0, STATIC, .unit = "fit_sense" },
1612  { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_COLOR, {.str = "black@0"}, .flags = DYNAMIC },
1613  { "corner_rounding", "Corner rounding radius", OFFSET(corner_rounding), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, .flags = DYNAMIC },
1614  { "lut", "Path to custom LUT file to apply", OFFSET(lut_filename), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = STATIC },
1615  { "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" },
1616  { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_UNKNOWN }, 0, 0, STATIC, .unit = "lut_type" },
1617  { "native", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NATIVE }, 0, 0, STATIC, .unit = "lut_type" },
1618  { "normalized", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_NORMALIZED }, 0, 0, STATIC, .unit = "lut_type" },
1619  { "conversion", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = PL_LUT_CONVERSION }, 0, 0, STATIC, .unit = "lut_type" },
1620 
1621  { "extra_opts", "Pass extra libplacebo-specific options using a :-separated list of key=value pairs", OFFSET(extra_opts), AV_OPT_TYPE_DICT, .flags = DYNAMIC },
1622 #if PL_API_VER >= 351
1623  { "shader_cache", "Set shader cache path", OFFSET(shader_cache), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = STATIC },
1624 #endif
1625 
1626  {"colorspace", "select colorspace", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_SPC_NB-1, DYNAMIC, .unit = "colorspace"},
1627  {"auto", "keep the same colorspace", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1628  {"gbr", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_RGB}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1629  {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1630  {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1631  {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT470BG}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1632  {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1633  {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1634  {"ycgco", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_YCGCO}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1635  {"bt2020nc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_NCL}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1636  {"bt2020c", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_BT2020_CL}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1637  {"ictcp", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_SPC_ICTCP}, INT_MIN, INT_MAX, STATIC, .unit = "colorspace"},
1638 
1639  {"range", "select color range", OFFSET(color_range), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_RANGE_NB-1, DYNAMIC, .unit = "range"},
1640  {"auto", "keep the same color range", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, STATIC, .unit = "range"},
1641  {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, STATIC, .unit = "range"},
1642  {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, STATIC, .unit = "range"},
1643  {"limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"},
1644  {"tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"},
1645  {"mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, STATIC, .unit = "range"},
1646  {"full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"},
1647  {"pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"},
1648  {"jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, STATIC, .unit = "range"},
1649 
1650  {"color_primaries", "select color primaries", OFFSET(color_primaries), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_PRI_NB-1, DYNAMIC, .unit = "color_primaries"},
1651  {"auto", "keep the same color primaries", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1652  {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1653  {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1654  {"bt470m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT470M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1655  {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT470BG}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1656  {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1657  {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1658  {"film", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_FILM}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1659  {"bt2020", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_BT2020}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1660  {"smpte428", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE428}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1661  {"smpte431", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE431}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1662  {"smpte432", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_SMPTE432}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1663  {"jedec-p22", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_JEDEC_P22}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1664  {"ebu3213", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_PRI_EBU3213}, INT_MIN, INT_MAX, STATIC, .unit = "color_primaries"},
1665 
1666  {"color_trc", "select color transfer", OFFSET(color_trc), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVCOL_TRC_NB-1, DYNAMIC, .unit = "color_trc"},
1667  {"auto", "keep the same color transfer", 0, AV_OPT_TYPE_CONST, {.i64=-1}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1668  {"bt709", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT709}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1669  {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_UNSPECIFIED}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1670  {"bt470m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA22}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1671  {"bt470bg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_GAMMA28}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1672  {"smpte170m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE170M}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1673  {"smpte240m", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE240M}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1674  {"linear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_LINEAR}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1675  {"iec61966-2-4", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_IEC61966_2_4}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1676  {"bt1361e", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT1361_ECG}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1677  {"iec61966-2-1", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_IEC61966_2_1}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1678  {"bt2020-10", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT2020_10}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1679  {"bt2020-12", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_BT2020_12}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1680  {"smpte2084", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_SMPTE2084}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1681  {"arib-std-b67", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_TRC_ARIB_STD_B67}, INT_MIN, INT_MAX, STATIC, .unit = "color_trc"},
1682 
1683  {"rotate", "rotate the input clockwise", OFFSET(rotation), AV_OPT_TYPE_INT, {.i64=PL_ROTATION_0}, PL_ROTATION_0, PL_ROTATION_360, DYNAMIC, .unit = "rotation"},
1684  {"0", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_0}, .flags = STATIC, .unit = "rotation"},
1685  {"90", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_90}, .flags = STATIC, .unit = "rotation"},
1686  {"180", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_180}, .flags = STATIC, .unit = "rotation"},
1687  {"270", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_270}, .flags = STATIC, .unit = "rotation"},
1688  {"360", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PL_ROTATION_360}, .flags = STATIC, .unit = "rotation"},
1689 
1690  {"alpha_mode", "select alpha moda", OFFSET(alpha_mode), AV_OPT_TYPE_INT, {.i64=-1}, -1, AVALPHA_MODE_NB-1, DYNAMIC, .unit = "alpha_mode"},
1691  {"auto", "keep the same alpha mode", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
1692  {"unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
1693  {"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_UNSPECIFIED}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
1694  {"premultiplied", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_PREMULTIPLIED}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
1695  {"straight", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVALPHA_MODE_STRAIGHT}, 0, 0, DYNAMIC, .unit = "alpha_mode"},
1696 
1697  { "upscaler", "Upscaler function", OFFSET(upscaler), AV_OPT_TYPE_STRING, {.str = "spline36"}, .flags = DYNAMIC },
1698  { "downscaler", "Downscaler function", OFFSET(downscaler), AV_OPT_TYPE_STRING, {.str = "mitchell"}, .flags = DYNAMIC },
1699  { "frame_mixer", "Frame mixing function", OFFSET(frame_mixer), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = DYNAMIC },
1700  { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC },
1701  { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
1702  { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
1703  { "apply_dolbyvision", "Apply Dolby Vision metadata", OFFSET(apply_dovi), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
1704 
1705  { "deinterlace", "Deinterlacing mode", OFFSET(deinterlace), AV_OPT_TYPE_INT, {.i64 = PL_DEINTERLACE_WEAVE}, 0, PL_DEINTERLACE_ALGORITHM_COUNT - 1, DYNAMIC, .unit = "deinterlace" },
1706  { "weave", "Weave fields together (no-op)", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_WEAVE}, 0, 0, STATIC, .unit = "deinterlace" },
1707  { "bob", "Naive bob deinterlacing", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0, STATIC, .unit = "deinterlace" },
1708  { "yadif", "Yet another deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0, STATIC, .unit = "deinterlace" },
1709 #if PL_API_VER >= 353
1710  { "bwdif", "Bob weaver deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BWDIF}, 0, 0, STATIC, .unit = "deinterlace" },
1711 #endif
1712  { "skip_spatial_check", "Skip yadif spatial check", OFFSET(skip_spatial_check), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1713  { "send_fields", "Output a frame for each field", OFFSET(send_fields), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1714 
1715  { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1716  { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC },
1717  { "deband_threshold", "Deband threshold", OFFSET(deband_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 4.0}, 0.0, 1024.0, DYNAMIC },
1718  { "deband_radius", "Deband radius", OFFSET(deband_radius), AV_OPT_TYPE_FLOAT, {.dbl = 16.0}, 0.0, 1024.0, DYNAMIC },
1719  { "deband_grain", "Deband grain", OFFSET(deband_grain), AV_OPT_TYPE_FLOAT, {.dbl = 6.0}, 0.0, 1024.0, DYNAMIC },
1720 
1721  { "brightness", "Brightness boost", OFFSET(brightness), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, -1.0, 1.0, DYNAMIC },
1722  { "contrast", "Contrast gain", OFFSET(contrast), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 16.0, DYNAMIC },
1723  { "saturation", "Saturation gain", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 16.0, DYNAMIC },
1724  { "hue", "Hue shift", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, -M_PI, M_PI, DYNAMIC },
1725  { "gamma", "Gamma adjustment", OFFSET(gamma), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 16.0, DYNAMIC },
1726 
1727  { "peak_detect", "Enable dynamic peak detection for HDR tone-mapping", OFFSET(peakdetect), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
1728  { "smoothing_period", "Peak detection smoothing period", OFFSET(smoothing), AV_OPT_TYPE_FLOAT, {.dbl = 100.0}, 0.0, 1000.0, DYNAMIC },
1729  { "scene_threshold_low", "Scene change low threshold", OFFSET(scene_low), AV_OPT_TYPE_FLOAT, {.dbl = 5.5}, -1.0, 100.0, DYNAMIC },
1730  { "scene_threshold_high", "Scene change high threshold", OFFSET(scene_high), AV_OPT_TYPE_FLOAT, {.dbl = 10.0}, -1.0, 100.0, DYNAMIC },
1731  { "percentile", "Peak detection percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl = 99.995}, 0.0, 100.0, DYNAMIC },
1732 
1733  { "gamut_mode", "Gamut-mapping mode", OFFSET(gamut_mode), AV_OPT_TYPE_INT, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, GAMUT_MAP_COUNT - 1, DYNAMIC, .unit = "gamut_mode" },
1734  { "clip", "Hard-clip (RGB per-channel)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_CLIP}, 0, 0, STATIC, .unit = "gamut_mode" },
1735  { "perceptual", "Colorimetric soft clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_PERCEPTUAL}, 0, 0, STATIC, .unit = "gamut_mode" },
1736  { "relative", "Relative colorimetric clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_RELATIVE}, 0, 0, STATIC, .unit = "gamut_mode" },
1737  { "saturation", "Saturation mapping (RGB -> RGB)", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_SATURATION}, 0, 0, STATIC, .unit = "gamut_mode" },
1738  { "absolute", "Absolute colorimetric clipping", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_ABSOLUTE}, 0, 0, STATIC, .unit = "gamut_mode" },
1739  { "desaturate", "Colorimetrically desaturate colors towards white", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_DESATURATE}, 0, 0, STATIC, .unit = "gamut_mode" },
1740  { "darken", "Colorimetric clip with bias towards darkening image to fit gamut", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_DARKEN}, 0, 0, STATIC, .unit = "gamut_mode" },
1741  { "warn", "Highlight out-of-gamut colors", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_HIGHLIGHT}, 0, 0, STATIC, .unit = "gamut_mode" },
1742  { "linear", "Linearly reduce chromaticity to fit gamut", 0, AV_OPT_TYPE_CONST, {.i64 = GAMUT_MAP_LINEAR}, 0, 0, STATIC, .unit = "gamut_mode" },
1743  { "tonemapping", "Tone-mapping algorithm", OFFSET(tonemapping), AV_OPT_TYPE_INT, {.i64 = TONE_MAP_AUTO}, 0, TONE_MAP_COUNT - 1, DYNAMIC, .unit = "tonemap" },
1744  { "auto", "Automatic selection", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_AUTO}, 0, 0, STATIC, .unit = "tonemap" },
1745  { "clip", "No tone mapping (clip", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_CLIP}, 0, 0, STATIC, .unit = "tonemap" },
1746 #if PL_API_VER >= 246
1747  { "st2094-40", "SMPTE ST 2094-40", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_ST2094_40}, 0, 0, STATIC, .unit = "tonemap" },
1748  { "st2094-10", "SMPTE ST 2094-10", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_ST2094_10}, 0, 0, STATIC, .unit = "tonemap" },
1749 #endif
1750  { "bt.2390", "ITU-R BT.2390 EETF", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_BT2390}, 0, 0, STATIC, .unit = "tonemap" },
1751  { "bt.2446a", "ITU-R BT.2446 Method A", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_BT2446A}, 0, 0, STATIC, .unit = "tonemap" },
1752  { "spline", "Single-pivot polynomial spline", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_SPLINE}, 0, 0, STATIC, .unit = "tonemap" },
1753  { "reinhard", "Reinhard", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_REINHARD}, 0, 0, STATIC, .unit = "tonemap" },
1754  { "mobius", "Mobius", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_MOBIUS}, 0, 0, STATIC, .unit = "tonemap" },
1755  { "hable", "Filmic tone-mapping (Hable)", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_HABLE}, 0, 0, STATIC, .unit = "tonemap" },
1756  { "gamma", "Gamma function with knee", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_GAMMA}, 0, 0, STATIC, .unit = "tonemap" },
1757  { "linear", "Perceptually linear stretch", 0, AV_OPT_TYPE_CONST, {.i64 = TONE_MAP_LINEAR}, 0, 0, STATIC, .unit = "tonemap" },
1758  { "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 },
1759  { "inverse_tonemapping", "Inverse tone mapping (range expansion)", OFFSET(inverse_tonemapping), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1760  { "tonemapping_lut_size", "Tone-mapping LUT size", OFFSET(tonemapping_lut_size), AV_OPT_TYPE_INT, {.i64 = 256}, 2, 1024, DYNAMIC },
1761  { "contrast_recovery", "HDR contrast recovery strength", OFFSET(contrast_recovery), AV_OPT_TYPE_FLOAT, {.dbl = 0.30}, 0.0, 3.0, DYNAMIC },
1762  { "contrast_smoothness", "HDR contrast recovery smoothness", OFFSET(contrast_smoothness), AV_OPT_TYPE_FLOAT, {.dbl = 3.50}, 1.0, 32.0, DYNAMIC },
1763 
1764  { "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" },
1765  { "none", "Disable dithering", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, STATIC, .unit = "dither" },
1766  { "blue", "Blue noise", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_BLUE_NOISE}, 0, 0, STATIC, .unit = "dither" },
1767  { "ordered", "Ordered LUT", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_ORDERED_LUT}, 0, 0, STATIC, .unit = "dither" },
1768  { "ordered_fixed", "Fixed function ordered", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_ORDERED_FIXED}, 0, 0, STATIC, .unit = "dither" },
1769  { "white", "White noise", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DITHER_WHITE_NOISE}, 0, 0, STATIC, .unit = "dither" },
1770  { "dither_lut_size", "Dithering LUT size", OFFSET(dither_lut_size), AV_OPT_TYPE_INT, {.i64 = 6}, 1, 8, STATIC },
1771  { "dither_temporal", "Enable temporal dithering", OFFSET(dither_temporal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1772 
1773  { "cones", "Colorblindness adaptation model", OFFSET(cones), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, PL_CONE_LMS, DYNAMIC, .unit = "cone" },
1774  { "l", "L cone", 0, AV_OPT_TYPE_CONST, {.i64 = PL_CONE_L}, 0, 0, STATIC, .unit = "cone" },
1775  { "m", "M cone", 0, AV_OPT_TYPE_CONST, {.i64 = PL_CONE_M}, 0, 0, STATIC, .unit = "cone" },
1776  { "s", "S cone", 0, AV_OPT_TYPE_CONST, {.i64 = PL_CONE_S}, 0, 0, STATIC, .unit = "cone" },
1777  { "cone-strength", "Colorblindness adaptation strength", OFFSET(cone_str), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 10.0, DYNAMIC },
1778 
1779  { "custom_shader_path", "Path to custom user shader (mpv .hook format)", OFFSET(shader_path), AV_OPT_TYPE_STRING, .flags = STATIC },
1780  { "custom_shader_bin", "Custom user shader as binary (mpv .hook format)", OFFSET(shader_bin), AV_OPT_TYPE_BINARY, .flags = STATIC },
1781 
1782  /* Performance/quality tradeoff options */
1783  { "skip_aa", "Skip anti-aliasing", OFFSET(skip_aa), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1784  { "disable_linear", "Disable linear scaling", OFFSET(disable_linear), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1785  { "disable_builtin", "Disable built-in scalers", OFFSET(disable_builtin), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1786  { "force_dither", "Force dithering", OFFSET(force_dither), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1787  { "disable_fbos", "Force-disable FBOs", OFFSET(disable_fbos), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
1788  { NULL },
1789 };
1790 
1791 AVFILTER_DEFINE_CLASS(libplacebo);
1792 
1794  {
1795  .name = "default",
1796  .type = AVMEDIA_TYPE_VIDEO,
1797  .config_props = &libplacebo_config_output,
1798  },
1799 };
1800 
1802  .p.name = "libplacebo",
1803  .p.description = NULL_IF_CONFIG_SMALL("Apply various GPU filters from libplacebo"),
1804  .p.priv_class = &libplacebo_class,
1806  .priv_size = sizeof(LibplaceboContext),
1807  .init = &libplacebo_init,
1813  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
1814 };
flags
const SwsFlags flags[]
Definition: swscale.c:61
formats
formats
Definition: signature.h:47
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:117
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:88
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:134
av_fifo_drain2
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
Definition: fifo.c:266
LibplaceboContext::colorspace
int colorspace
Definition: vf_libplacebo.c:218
dithering
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion dithering
Definition: swscale-v2.txt:9
VAR_IH
@ VAR_IH
Definition: vf_libplacebo.c:123
LibplaceboContext::out_format
enum AVPixelFormat out_format
Definition: vf_libplacebo.c:192
AVVulkanDeviceContext::phys_dev
VkPhysicalDevice phys_dev
Physical device.
Definition: hwcontext_vulkan.h:79
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
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
Definition: writing_filters.txt:88
level
uint8_t level
Definition: svq3.c:208
AVCOL_PRI_EBU3213
@ AVCOL_PRI_EBU3213
EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors.
Definition: pixfmt.h:652
mix
static int mix(int c0, int c1)
Definition: 4xm.c:717
LibplaceboContext::fps_string
char * fps_string
Definition: vf_libplacebo.c:197
AVERROR
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
opt.h
LibplaceboContext::percentile
float percentile
Definition: vf_libplacebo.c:270
LibplaceboContext::deband
int deband
Definition: vf_libplacebo.c:252
AVALPHA_MODE_STRAIGHT
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition: pixfmt.h:803
var_name
var_name
Definition: noise.c:46
AVALPHA_MODE_PREMULTIPLIED
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
Definition: pixfmt.h:802
LibplaceboContext::deband_iterations
int deband_iterations
Definition: vf_libplacebo.c:253
LibplaceboContext::deband_threshold
float deband_threshold
Definition: vf_libplacebo.c:254
LibplaceboContext::gamut_mode
int gamut_mode
Definition: vf_libplacebo.c:273
out
FILE * out
Definition: movenc.c:55
VAR_IN_H
@ VAR_IN_H
Definition: vf_libplacebo.c:123
LibplaceboContext::crop_y_pexpr
AVExpr * crop_y_pexpr
Definition: vf_libplacebo.c:204
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:659
GAMUT_MAP_LINEAR
@ GAMUT_MAP_LINEAR
Definition: vf_libplacebo.c:93
LibplaceboContext::linear_tex
pl_tex linear_tex
Definition: vf_libplacebo.c:183
LibplaceboContext::deinterlace
int deinterlace
Definition: vf_libplacebo.c:247
LibplaceboContext::contrast
float contrast
Definition: vf_libplacebo.c:260
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1067
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:775
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3447
VAR_OUT_T
@ VAR_OUT_T
Definition: vf_libplacebo.c:138
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
RET
#define RET(x)
Definition: vulkan.h:66
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:670
av_dict_count
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:37
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
TONE_MAP_SPLINE
@ TONE_MAP_SPLINE
Definition: vf_libplacebo.c:75
pl_options_t::sigmoid_params
struct pl_sigmoid_params sigmoid_params
Definition: vf_libplacebo.c:56
saturation
static IPT saturation(const CmsCtx *ctx, IPT ipt)
Definition: cms.c:559
TONE_MAP_BT2446A
@ TONE_MAP_BT2446A
Definition: vf_libplacebo.c:74
AV_FRAME_DATA_DOVI_METADATA
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
Definition: frame.h:208
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
int64_t
long long int64_t
Definition: coverity.c:34
GAMUT_MAP_CLIP
@ GAMUT_MAP_CLIP
Definition: vf_libplacebo.c:85
inlink
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
Definition: filter_design.txt:212
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
AV_FRAME_DATA_FILM_GRAIN_PARAMS
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
Definition: frame.h:188
VAR_OHSUB
@ VAR_OHSUB
Definition: vf_libplacebo.c:135
LibplaceboContext::apply_filmgrain
int apply_filmgrain
Definition: vf_libplacebo.c:216
find_scaler
static int find_scaler(AVFilterContext *avctx, const struct pl_filter_config **opt, const char *name, int frame_mixing)
Definition: vf_libplacebo.c:375
normalize.log
log
Definition: normalize.py:21
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
VAR_IN_IDX
@ VAR_IN_IDX
Definition: vf_libplacebo.c:121
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:565
update_settings
static int update_settings(AVFilterContext *ctx)
Definition: vf_libplacebo.c:421
av_fifo_peek
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.
Definition: fifo.c:255
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:683
pl_options_t::deband_params
struct pl_deband_params deband_params
Definition: vf_libplacebo.c:55
AVVulkanDeviceContext::get_proc_addr
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
Definition: hwcontext_vulkan.h:69
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:529
GAMUT_MAP_PERCEPTUAL
@ GAMUT_MAP_PERCEPTUAL
Definition: vf_libplacebo.c:86
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:767
pl_av_log
static void pl_av_log(void *log_ctx, enum pl_log_level level, const char *msg)
Definition: vf_libplacebo.c:310
AVOption
AVOption.
Definition: opt.h:429
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:710
b
#define b
Definition: input.c:42
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:664
LibplaceboContext
Definition: vf_libplacebo.c:170
LibplaceboInput::status
int status
Definition: vf_libplacebo.c:152
LibplaceboContext::crop_h_pexpr
AVExpr * crop_h_pexpr
Definition: vf_libplacebo.c:204
av_pix_fmt_desc_next
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:3454
TONE_MAP_BT2390
@ TONE_MAP_BT2390
Definition: vf_libplacebo.c:73
AVVulkanDeviceContext::inst
VkInstance inst
Vulkan instance.
Definition: hwcontext_vulkan.h:74
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:75
SCALE_FORCE_OAR_NB
@ SCALE_FORCE_OAR_NB
Definition: scale_eval.h:28
AVCOL_PRI_JEDEC_P22
@ AVCOL_PRI_JEDEC_P22
Definition: pixfmt.h:653
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
LibplaceboContext::tex
pl_tex tex[4]
Definition: vf_libplacebo.c:178
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:691
ff_scale_eval_dimensions
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.
Definition: scale_eval.c:57
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:677
handle_input
static int handle_input(AVFilterContext *ctx, LibplaceboInput *input)
Definition: vf_libplacebo.c:1170
AVFilterContext::hw_device_ctx
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
Definition: avfilter.h:356
av_get_bits_per_pixel
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:3399
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2964
LibplaceboContext::sigmoid
int sigmoid
Definition: vf_libplacebo.c:239
LibplaceboContext::crop_h_expr
char * crop_h_expr
Definition: vf_libplacebo.c:200
AVDictionary
Definition: dict.c:32
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
pl_get_mapped_avframe
static AVFrame * pl_get_mapped_avframe(const struct pl_frame *frame)
Definition: vf_libplacebo.c:42
map_frame
static bool map_frame(pl_gpu gpu, pl_tex *tex, const struct pl_source_frame *src, struct pl_frame *out)
Definition: vf_libplacebo.c:1137
VAR_OT
@ VAR_OT
Definition: vf_libplacebo.c:138
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
pl_options_t::color_adjustment
struct pl_color_adjustment color_adjustment
Definition: vf_libplacebo.c:57
video.h
LibplaceboContext::vkctx
FFVulkanContext vkctx
Definition: vf_libplacebo.c:172
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:702
ff_make_formats_list_singleton
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition: formats.c:545
VAR_CROP_H
@ VAR_CROP_H
Definition: vf_libplacebo.c:127
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
libplacebo_activate
static int libplacebo_activate(AVFilterContext *ctx)
Definition: vf_libplacebo.c:1228
roundf
static av_always_inline av_const float roundf(float x)
Definition: libm.h:453
AV_HWDEVICE_TYPE_VULKAN
@ AV_HWDEVICE_TYPE_VULKAN
Definition: hwcontext.h:39
FIT_NONE
@ FIT_NONE
Definition: vf_libplacebo.c:159
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:655
formats.h
av_expr_parse
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.
Definition: eval.c:710
unmap_frame
static void unmap_frame(pl_gpu gpu, struct pl_frame *frame, const struct pl_source_frame *src)
Definition: vf_libplacebo.c:1158
VAR_VSUB
@ VAR_VSUB
Definition: vf_libplacebo.c:134
libplacebo_config_output
static int libplacebo_config_output(AVFilterLink *outlink)
Definition: vf_libplacebo.c:1441
VAR_PH
@ VAR_PH
Definition: vf_libplacebo.c:129
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1517
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:696
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:651
fifo.h
AV_OPT_TYPE_BINARY
@ 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...
Definition: opt.h:286
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:675
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...
Definition: file.c:55
LibplaceboContext::pos_w_pexpr
AVExpr * pos_w_pexpr
Definition: vf_libplacebo.c:205
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:289
LibplaceboContext::shader_bin_len
int shader_bin_len
Definition: vf_libplacebo.c:293
fail
#define fail()
Definition: checkasm.h:204
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
FIT_TARGET
@ FIT_TARGET
Definition: vf_libplacebo.c:165
vulkan_filter.h
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
dummy
int dummy
Definition: motion.c:66
AVCOL_RANGE_NB
@ AVCOL_RANGE_NB
Not part of ABI.
Definition: pixfmt.h:768
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:667
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:208
LibplaceboContext::nb_inputs
int nb_inputs
Definition: vf_libplacebo.c:187
lock_queue
static void lock_queue(AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
Definition: hwcontext_vulkan.c:1819
LibplaceboContext::pos_y_expr
char * pos_y_expr
Definition: vf_libplacebo.c:201
pts
static int64_t pts
Definition: transcode_aac.c:644
LibplaceboContext::crop_y_expr
char * crop_y_expr
Definition: vf_libplacebo.c:199
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:156
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
AVRational::num
int num
Numerator.
Definition: rational.h:59
LibplaceboContext::contrast_smoothness
float contrast_smoothness
Definition: vf_libplacebo.c:279
VAR_CROP_W
@ VAR_CROP_W
Definition: vf_libplacebo.c:126
AV_SIDE_DATA_PROP_SIZE_DEPENDENT
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
Definition: frame.h:309
LibplaceboInput::renderer
pl_renderer renderer
Definition: vf_libplacebo.c:146
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:666
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
LibplaceboContext::fit_mode
int fit_mode
Definition: vf_libplacebo.c:214
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
LibplaceboContext::extra_opts
AVDictionary * extra_opts
Definition: vf_libplacebo.c:224
VAR_OW
@ VAR_OW
Definition: vf_libplacebo.c:124
LibplaceboContext::antiringing
float antiringing
Definition: vf_libplacebo.c:238
preset
preset
Definition: vf_curves.c:47
avassert.h
AVVulkanDeviceQueueFamily::num
int num
Definition: hwcontext_vulkan.h:37
LibplaceboContext::pos_w_expr
char * pos_w_expr
Definition: vf_libplacebo.c:202
LibplaceboContext::disable_linear
int disable_linear
Definition: vf_libplacebo.c:241
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
VAR_VARS_NB
@ VAR_VARS_NB
Definition: vf_libplacebo.c:140
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
LibplaceboContext::crop_x_expr
char * crop_x_expr
Definition: vf_libplacebo.c:199
FFFilter
Definition: filters.h:266
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:628
LibplaceboContext::lut
struct pl_custom_lut * lut
Definition: vf_libplacebo.c:179
FIT_CONTAIN
@ FIT_CONTAIN
Definition: vf_libplacebo.c:157
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1620
ref_frame
static const AVFrame * ref_frame(const struct pl_frame_mix *mix)
Definition: vf_libplacebo.c:852
output_frame
static int output_frame(AVFilterContext *ctx, int64_t pts)
Definition: vf_libplacebo.c:959
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCOL_PRI_NB
@ AVCOL_PRI_NB
Not part of ABI.
Definition: pixfmt.h:654
LibplaceboContext::force_original_aspect_ratio
int force_original_aspect_ratio
Definition: vf_libplacebo.c:210
AVCOL_TRC_BT1361_ECG
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
Definition: pixfmt.h:674
LibplaceboContext::force_dither
int force_dither
Definition: vf_libplacebo.c:243
LibplaceboContext::inputs
LibplaceboInput * inputs
Definition: vf_libplacebo.c:186
discard_frame
static void discard_frame(const struct pl_source_frame *src)
Definition: vf_libplacebo.c:1164
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:697
AVDictionaryEntry::key
char * key
Definition: dict.h:91
LibplaceboContext::opts
pl_options opts
Definition: vf_libplacebo.c:234
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:705
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
libplacebo_uninit
static void libplacebo_uninit(AVFilterContext *avctx)
Definition: vf_libplacebo.c:803
LibplaceboContext::frame_mixer
char * frame_mixer
Definition: vf_libplacebo.c:237
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
filters.h
TONE_MAP_LINEAR
@ TONE_MAP_LINEAR
Definition: vf_libplacebo.c:80
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
GAMUT_MAP_HIGHLIGHT
@ GAMUT_MAP_HIGHLIGHT
Definition: vf_libplacebo.c:92
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
LibplaceboContext::tonemapping
int tonemapping
Definition: vf_libplacebo.c:274
AVCOL_PRI_SMPTE428
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition: pixfmt.h:648
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVExpr
Definition: eval.c:158
LibplaceboContext::crop_w_expr
char * crop_w_expr
Definition: vf_libplacebo.c:200
LibplaceboContext::disable_builtin
int disable_builtin
Definition: vf_libplacebo.c:242
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
LibplaceboContext::color_trc
int color_trc
Definition: vf_libplacebo.c:221
libplacebo_process_command
static int libplacebo_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_libplacebo.c:839
VAR_IN_T
@ VAR_IN_T
Definition: vf_libplacebo.c:137
ff_vf_libplacebo
const FFFilter ff_vf_libplacebo
Definition: vf_libplacebo.c:1801
LibplaceboContext::w_expr
char * w_expr
Definition: vf_libplacebo.c:195
AVCOL_PRI_SMPTE240M
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
Definition: pixfmt.h:645
LibplaceboInput
Definition: vf_libplacebo.c:144
color_range
color_range
Definition: vf_selectivecolor.c:43
pl_options_t::peak_detect_params
struct pl_peak_detect_params peak_detect_params
Definition: vf_libplacebo.c:58
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
LibplaceboContext::force_divisible_by
int force_divisible_by
Definition: vf_libplacebo.c:211
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
NAN
#define NAN
Definition: mathematics.h:115
av_file_unmap
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:142
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:643
arg
const char * arg
Definition: jacosubdec.c:67
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:644
if
if(ret)
Definition: filter_design.txt:179
av_log_get_level
int av_log_get_level(void)
Get the current log level.
Definition: log.c:470
get_tonemapping_func
static const struct pl_tone_map_function * get_tonemapping_func(int tm)
Definition: vf_libplacebo.c:327
VAR_IW
@ VAR_IW
Definition: vf_libplacebo.c:122
AVVulkanDeviceContext
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_vulkan.h:59
TONE_MAP_AUTO
@ TONE_MAP_AUTO
Definition: vf_libplacebo.c:69
opts
AVDictionary * opts
Definition: movenc.c:51
LibplaceboContext::fit_sense
int fit_sense
Definition: vf_libplacebo.c:215
GAMUT_MAP_ABSOLUTE
@ GAMUT_MAP_ABSOLUTE
Definition: vf_libplacebo.c:89
VAR_PW
@ VAR_PW
Definition: vf_libplacebo.c:128
NULL
#define NULL
Definition: coverity.c:32
LibplaceboContext::dither_temporal
int dither_temporal
Definition: vf_libplacebo.c:284
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
AVVulkanDeviceContext::nb_enabled_dev_extensions
int nb_enabled_dev_extensions
Definition: hwcontext_vulkan.h:113
LibplaceboContext::skip_aa
int skip_aa
Definition: vf_libplacebo.c:240
SCALE_FORCE_OAR_DISABLE
@ SCALE_FORCE_OAR_DISABLE
Definition: scale_eval.h:25
LibplaceboContext::shader_bin
void * shader_bin
Definition: vf_libplacebo.c:292
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
LibplaceboContext::cones
int cones
Definition: vf_libplacebo.c:287
AVCOL_TRC_IEC61966_2_4
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:673
fit_mode
fit_mode
Definition: vf_libplacebo.c:155
ff_append_inpad_free_name
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:132
LibplaceboContext::brightness
float brightness
Definition: vf_libplacebo.c:259
activate
filter_frame For filters that do not use the activate() callback
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
FIT_COVER
@ FIT_COVER
Definition: vf_libplacebo.c:158
fit_sense
fit_sense
Definition: vf_libplacebo.c:164
AVVulkanDeviceContext::unlock_queue
void(* unlock_queue)(struct AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
Similar to lock_queue(), unlocks a queue.
Definition: hwcontext_vulkan.h:178
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition: opt.h:290
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:282
LibplaceboContext::gpu
pl_gpu gpu
Definition: vf_libplacebo.c:177
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:638
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:520
parseutils.h
VAR_OUT_W
@ VAR_OUT_W
Definition: vf_libplacebo.c:124
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
AVVulkanDeviceContext::nb_qf
int nb_qf
Definition: hwcontext_vulkan.h:189
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:209
TONE_MAP_COUNT
@ TONE_MAP_COUNT
Definition: vf_libplacebo.c:81
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:227
LibplaceboContext::fillcolor
uint8_t fillcolor[4]
Definition: vf_libplacebo.c:193
double
double
Definition: af_crystalizer.c:132
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:676
AVCOL_SPC_YCGCO
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
Definition: pixfmt.h:699
VAR_OUT_H
@ VAR_OUT_H
Definition: vf_libplacebo.c:125
input_init
static int input_init(AVFilterContext *avctx, LibplaceboInput *input, int idx)
Definition: vf_libplacebo.c:673
AVVulkanDeviceContext::qf
AVVulkanDeviceQueueFamily qf[64]
Queue families used.
Definition: hwcontext_vulkan.h:188
FFVulkanContext
Definition: vulkan.h:274
ff_all_color_spaces
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition: formats.c:646
AVFilterFormats::refcount
unsigned refcount
number of references to this list
Definition: formats.h:68
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1464
LibplaceboContext::nb_active
int nb_active
Definition: vf_libplacebo.c:188
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:733
parse_shader
static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
Definition: vf_libplacebo.c:538
set_gamut_mode
static void set_gamut_mode(struct pl_color_map_params *p, int gamut_mode)
Definition: vf_libplacebo.c:347
libplacebo_config_input
static int libplacebo_config_input(AVFilterLink *inlink)
Definition: vf_libplacebo.c:1414
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:121
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:198
VAR_CW
@ VAR_CW
Definition: vf_libplacebo.c:126
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:647
LibplaceboInput::status_pts
int64_t status_pts
Definition: vf_libplacebo.c:151
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:207
LibplaceboContext::cone_str
float cone_str
Definition: vf_libplacebo.c:288
LibplaceboContext::reset_sar
int reset_sar
Definition: vf_libplacebo.c:212
LibplaceboContext::have_hwdevice
int have_hwdevice
Definition: vf_libplacebo.c:231
color_primaries
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition: csp.c:76
init_vulkan
static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx)
Definition: vf_libplacebo.c:694
LibplaceboContext::hue
float hue
Definition: vf_libplacebo.c:262
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:678
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:650
eval.h
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
LibplaceboContext::lut_type
enum pl_lut_type lut_type
Definition: vf_libplacebo.c:209
AVFifo
Definition: fifo.c:35
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:669
AVCOL_PRI_FILM
@ AVCOL_PRI_FILM
colour filters using Illuminant C
Definition: pixfmt.h:646
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_acrusher.c:307
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(libplacebo)
LibplaceboContext::deband_grain
float deband_grain
Definition: vf_libplacebo.c:256
LibplaceboInput::mix
struct pl_frame_mix mix
temporary storage
Definition: vf_libplacebo.c:149
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:188
FIT_FILL
@ FIT_FILL
Definition: vf_libplacebo.c:156
LibplaceboContext::out_format_string
char * out_format_string
Definition: vf_libplacebo.c:191
LibplaceboContext::disable_fbos
int disable_fbos
Definition: vf_libplacebo.c:244
TONE_MAP_ST2094_10
@ TONE_MAP_ST2094_10
Definition: vf_libplacebo.c:72
LibplaceboContext::saturation
float saturation
Definition: vf_libplacebo.c:261
LibplaceboContext::num_hooks
int num_hooks
Definition: vf_libplacebo.c:295
TS2T
#define TS2T(ts, tb)
Definition: filters.h:482
AVALPHA_MODE_NB
@ AVALPHA_MODE_NB
Not part of ABI.
Definition: pixfmt.h:804
libplacebo_options
static const AVOption libplacebo_options[]
Definition: vf_libplacebo.c:1580
scale_eval.h
sigmoid
static float sigmoid(float x)
Definition: vf_dnn_detect.c:90
frame.h
ff_filter_process_command
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.
Definition: avfilter.c:905
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:725
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
TONE_MAP_HABLE
@ TONE_MAP_HABLE
Definition: vf_libplacebo.c:78
pl_options_alloc
#define pl_options_alloc(log)
Definition: vf_libplacebo.c:64
AVVulkanDeviceQueueFamily::idx
int idx
Definition: hwcontext_vulkan.h:35
ff_all_color_ranges
AVFilterFormats * ff_all_color_ranges(void)
Construct an AVFilterFormats representing all possible color ranges.
Definition: formats.c:662
LibplaceboContext::var_values
double var_values[VAR_VARS_NB]
Definition: vf_libplacebo.c:194
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
LibplaceboContext::normalize_sar
int normalize_sar
Definition: vf_libplacebo.c:213
GAMUT_MAP_SATURATION
@ GAMUT_MAP_SATURATION
Definition: vf_libplacebo.c:88
av_pix_fmt_desc_get_id
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:3466
TONE_MAP_MOBIUS
@ TONE_MAP_MOBIUS
Definition: vf_libplacebo.c:77
LibplaceboContext::corner_rounding
float corner_rounding
Definition: vf_libplacebo.c:207
LibplaceboContext::alpha_mode
int alpha_mode
Definition: vf_libplacebo.c:223
LibplaceboContext::apply_dovi
int apply_dovi
Definition: vf_libplacebo.c:217
VAR_POS_H
@ VAR_POS_H
Definition: vf_libplacebo.c:129
av_frame_side_data_remove_by_props
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.
Definition: side_data.c:117
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
LibplaceboContext::downscaler
char * downscaler
Definition: vf_libplacebo.c:236
fixed
#define fixed(width, name, value)
Definition: cbs_apv.c:77
LibplaceboContext::log
pl_log log
Definition: vf_libplacebo.c:175
LibplaceboContext::vulkan
pl_vulkan vulkan
Definition: vf_libplacebo.c:176
M_PI
#define M_PI
Definition: mathematics.h:67
AVVulkanDeviceContext::lock_queue
void(* lock_queue)(struct AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
Locks a queue, preventing other threads from submitting any command buffers to this queue.
Definition: hwcontext_vulkan.h:173
LibplaceboContext::pos_h_pexpr
AVExpr * pos_h_pexpr
Definition: vf_libplacebo.c:205
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:663
av_vkfmt_from_pixfmt
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.
Definition: hwcontext_stub.c:30
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
TONE_MAP_CLIP
@ TONE_MAP_CLIP
Definition: vf_libplacebo.c:70
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:698
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
get_log_level
static enum pl_log_level get_log_level(void)
Definition: vf_libplacebo.c:298
FIT_SENSE_NB
@ FIT_SENSE_NB
Definition: vf_libplacebo.c:167
ff_formats_unref
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to,...
Definition: formats.c:744
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
LibplaceboContext::pos_x_expr
char * pos_x_expr
Definition: vf_libplacebo.c:201
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
LibplaceboContext::upscaler
char * upscaler
Definition: vf_libplacebo.c:235
pl_options_t::params
struct pl_render_params params
Definition: vf_libplacebo.c:53
FIT_CONSTRAINT
@ FIT_CONSTRAINT
Definition: vf_libplacebo.c:166
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:701
pl_options_free
#define pl_options_free(ptr)
Definition: vf_libplacebo.c:65
av_gcd_q
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.
Definition: rational.c:184
LibplaceboContext::gamma
float gamma
Definition: vf_libplacebo.c:263
algo
Definition: dct.c:59
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
VAR_OVSUB
@ VAR_OVSUB
Definition: vf_libplacebo.c:136
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
LibplaceboInput::qstatus
enum pl_queue_status qstatus
Definition: vf_libplacebo.c:148
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:240
LibplaceboContext::tonemapping_lut_size
int tonemapping_lut_size
Definition: vf_libplacebo.c:277
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
LibplaceboContext::tonemapping_param
float tonemapping_param
Definition: vf_libplacebo.c:275
AV_PIX_FMT_FLAG_BE
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:116
LibplaceboContext::pos_h_expr
char * pos_h_expr
Definition: vf_libplacebo.c:202
LibplaceboContext::color_primaries
int color_primaries
Definition: vf_libplacebo.c:220
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
len
int len
Definition: vorbis_enc_data.h:426
var_names
static const char *const var_names[]
Definition: vf_libplacebo.c:97
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:693
LibplaceboContext::dithering
int dithering
Definition: vf_libplacebo.c:282
LibplaceboContext::scene_high
float scene_high
Definition: vf_libplacebo.c:269
STATIC
#define STATIC
Definition: vf_libplacebo.c:1577
drain_input_pts
static void drain_input_pts(LibplaceboInput *in, int64_t until)
Definition: vf_libplacebo.c:1221
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:650
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:750
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
LibplaceboContext::skip_spatial_check
int skip_spatial_check
Definition: vf_libplacebo.c:248
AV_SIDE_DATA_PROP_COLOR_DEPENDENT
@ AV_SIDE_DATA_PROP_COLOR_DEPENDENT
Side data depends on the video color space.
Definition: frame.h:316
parse_custom_lut
static int parse_custom_lut(AVFilterContext *avctx)
Definition: vf_libplacebo.c:400
LibplaceboInput::queue
pl_queue queue
Definition: vf_libplacebo.c:147
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
pl_options_t::dither_params
struct pl_dither_params dither_params
Definition: vf_libplacebo.c:60
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
GAMUT_MAP_DARKEN
@ GAMUT_MAP_DARKEN
Definition: vf_libplacebo.c:91
AVCOL_PRI_BT470M
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:641
ret
ret
Definition: filter_design.txt:187
pl_options_t::deinterlace_params
struct pl_deinterlace_params deinterlace_params
Definition: vf_libplacebo.c:54
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
pixfmt
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:367
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:75
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVALPHA_MODE_UNSPECIFIED
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition: pixfmt.h:801
frame
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
Definition: filter_design.txt:265
LibplaceboContext::scene_low
float scene_low
Definition: vf_libplacebo.c:268
VAR_OH
@ VAR_OH
Definition: vf_libplacebo.c:125
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:153
VAR_CH
@ VAR_CH
Definition: vf_libplacebo.c:127
LibplaceboContext::linear_rr
pl_renderer linear_rr
Definition: vf_libplacebo.c:182
unlock_queue
static void unlock_queue(AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
Definition: hwcontext_vulkan.c:1825
av_fifo_alloc2
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.
Definition: fifo.c:47
VAR_T
@ VAR_T
Definition: vf_libplacebo.c:137
LibplaceboContext::peakdetect
int peakdetect
Definition: vf_libplacebo.c:266
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3379
LibplaceboContext::deband_radius
float deband_radius
Definition: vf_libplacebo.c:255
LibplaceboInput::idx
int idx
Definition: vf_libplacebo.c:145
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:682
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
LibplaceboContext::contrast_recovery
float contrast_recovery
Definition: vf_libplacebo.c:278
VAR_IN_W
@ VAR_IN_W
Definition: vf_libplacebo.c:122
SCALE_FORCE_OAR_DECREASE
@ SCALE_FORCE_OAR_DECREASE
Definition: scale_eval.h:26
update_crops
static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, struct pl_frame *target, double target_pts)
Definition: vf_libplacebo.c:861
libplacebo_outputs
static const AVFilterPad libplacebo_outputs[]
Definition: vf_libplacebo.c:1793
SCALE_FORCE_OAR_INCREASE
@ SCALE_FORCE_OAR_INCREASE
Definition: scale_eval.h:27
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
VAR_HSUB
@ VAR_HSUB
Definition: vf_libplacebo.c:133
LibplaceboContext::inverse_tonemapping
int inverse_tonemapping
Definition: vf_libplacebo.c:276
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
LibplaceboContext::rotation
int rotation
Definition: vf_libplacebo.c:222
ff_all_alpha_modes
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition: formats.c:673
AVCOL_TRC_SMPTE170M
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:668
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
file.h
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
OFFSET
#define OFFSET(x)
Definition: vf_libplacebo.c:1576
VAR_SAR
@ VAR_SAR
Definition: vf_libplacebo.c:131
TONE_MAP_GAMMA
@ TONE_MAP_GAMMA
Definition: vf_libplacebo.c:79
LibplaceboContext::fps
AVRational fps
parsed FPS, or 0/0 for "none"
Definition: vf_libplacebo.c:198
input_uninit
static void input_uninit(LibplaceboInput *input)
Definition: vf_libplacebo.c:687
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
FIT_MODE_NB
@ FIT_MODE_NB
Definition: vf_libplacebo.c:161
desc
const char * desc
Definition: libsvtav1.c:79
AVVulkanDeviceContext::enabled_dev_extensions
const char *const * enabled_dev_extensions
Enabled device extensions.
Definition: hwcontext_vulkan.h:112
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:176
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
libplacebo_query_format
static int libplacebo_query_format(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_libplacebo.c:1324
FIT_SCALE_DOWN
@ FIT_SCALE_DOWN
Definition: vf_libplacebo.c:160
mem.h
VAR_IDX
@ VAR_IDX
Definition: vf_libplacebo.c:121
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:126
LibplaceboInput::out_pts
AVFifo * out_pts
timestamps of wanted output frames
Definition: vf_libplacebo.c:150
LibplaceboContext::crop_w_pexpr
AVExpr * crop_w_pexpr
Definition: vf_libplacebo.c:204
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
LibplaceboContext::pad_crop_ratio
float pad_crop_ratio
Definition: vf_libplacebo.c:206
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:651
AVDictionaryEntry
Definition: dict.h:90
TONE_MAP_ST2094_40
@ TONE_MAP_ST2094_40
Definition: vf_libplacebo.c:71
GAMUT_MAP_RELATIVE
@ GAMUT_MAP_RELATIVE
Definition: vf_libplacebo.c:87
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
VAR_POS_W
@ VAR_POS_W
Definition: vf_libplacebo.c:128
max_q
static AVRational max_q(AVRational a, AVRational b)
Definition: vf_libplacebo.c:1436
LibplaceboContext::smoothing
float smoothing
Definition: vf_libplacebo.c:267
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
pl_options_t::color_map_params
struct pl_color_map_params color_map_params
Definition: vf_libplacebo.c:59
TONE_MAP_REINHARD
@ TONE_MAP_REINHARD
Definition: vf_libplacebo.c:76
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
DYNAMIC
#define DYNAMIC
Definition: vf_libplacebo.c:1578
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
VAR_N
@ VAR_N
Definition: vf_libplacebo.c:139
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
LibplaceboContext::shader_path
char * shader_path
Definition: vf_libplacebo.c:291
VAR_A
@ VAR_A
Definition: vf_libplacebo.c:130
LibplaceboContext::crop_x_pexpr
AVExpr * crop_x_pexpr
Definition: vf_libplacebo.c:204
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVVulkanDeviceContext::device_features
VkPhysicalDeviceFeatures2 device_features
This structure should be set to the set of features that present and enabled during device creation.
Definition: hwcontext_vulkan.h:92
LibplaceboContext::color_range
int color_range
Definition: vf_libplacebo.c:219
AVDictionaryEntry::value
char * value
Definition: dict.h:92
AV_OPT_TYPE_STRING
@ 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...
Definition: opt.h:276
LibplaceboContext::dither_lut_size
int dither_lut_size
Definition: vf_libplacebo.c:283
LibplaceboContext::pos_x_pexpr
AVExpr * pos_x_pexpr
Definition: vf_libplacebo.c:205
libplacebo_init
static int libplacebo_init(AVFilterContext *avctx)
Definition: vf_libplacebo.c:557
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:692
LibplaceboContext::h_expr
char * h_expr
Definition: vf_libplacebo.c:196
VAR_DAR
@ VAR_DAR
Definition: vf_libplacebo.c:132
pl_options_t::cone_params
struct pl_cone_params cone_params
Definition: vf_libplacebo.c:61
AVCOL_SPC_ICTCP
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
Definition: pixfmt.h:706
AVVulkanDeviceQueueFamily::flags
VkQueueFlagBits flags
Definition: hwcontext_vulkan.h:41
LibplaceboContext::hooks
const struct pl_hook * hooks[2]
Definition: vf_libplacebo.c:294
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
GAMUT_MAP_COUNT
@ GAMUT_MAP_COUNT
Definition: vf_libplacebo.c:94
ff_scale_adjust_dimensions
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 ...
Definition: scale_eval.c:113
av_rescale_q_rnd
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.
Definition: mathematics.c:134
LibplaceboContext::lut_filename
char * lut_filename
Definition: vf_libplacebo.c:208
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
LibplaceboContext::pos_y_pexpr
AVExpr * pos_y_pexpr
Definition: vf_libplacebo.c:205
src
#define src
Definition: vp8dsp.c:248
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:63
log_cb
static void log_cb(cmsContext ctx, cmsUInt32Number error, const char *str)
Definition: fflcms2.c:24
GAMUT_MAP_DESATURATE
@ GAMUT_MAP_DESATURATE
Definition: vf_libplacebo.c:90
pl_options_t
Definition: vf_libplacebo.c:51
LibplaceboContext::send_fields
int send_fields
Definition: vf_libplacebo.c:249