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