FFmpeg
vf_zscale.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * zscale video filter using z.lib library
24  */
25 
26 #include <float.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include <zimg.h>
31 
32 #include "avfilter.h"
33 #include "formats.h"
34 #include "internal.h"
35 #include "video.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/eval.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/intreadwrite.h"
40 #include "libavutil/mathematics.h"
41 #include "libavutil/opt.h"
42 #include "libavutil/parseutils.h"
43 #include "libavutil/pixdesc.h"
44 #include "libavutil/imgutils.h"
45 
46 #define ZIMG_ALIGNMENT 32
47 
48 static const char *const var_names[] = {
49  "in_w", "iw",
50  "in_h", "ih",
51  "out_w", "ow",
52  "out_h", "oh",
53  "a",
54  "sar",
55  "dar",
56  "hsub",
57  "vsub",
58  "ohsub",
59  "ovsub",
60  NULL
61 };
62 
63 enum var_name {
76 };
77 
78 typedef struct ZScaleContext {
79  const AVClass *class;
80 
81  /**
82  * New dimensions. Special values are:
83  * 0 = original width/height
84  * -1 = keep original aspect
85  * -N = try to keep aspect but make sure it is divisible by N
86  */
87  int w, h;
88  int dither;
89  int filter;
91  int trc;
92  int primaries;
93  int range;
94  int chromal;
96  int trc_in;
98  int range_in;
100  char *size_str;
103  double param_a;
104  double param_b;
105 
106  char *w_expr; ///< width expression string
107  char *h_expr; ///< height expression string
108 
113 
115 
116  void *tmp;
117  size_t tmp_size;
118 
119  zimg_image_format src_format, dst_format;
120  zimg_image_format alpha_src_format, alpha_dst_format;
121  zimg_graph_builder_params alpha_params, params;
122  zimg_filter_graph *alpha_graph, *graph;
123 
124  enum AVColorSpace in_colorspace, out_colorspace;
126  enum AVColorPrimaries in_primaries, out_primaries;
127  enum AVColorRange in_range, out_range;
128  enum AVChromaLocation in_chromal, out_chromal;
129 } ZScaleContext;
130 
132 {
133  ZScaleContext *s = ctx->priv;
134  int ret;
135 
136  if (s->size_str && (s->w_expr || s->h_expr)) {
138  "Size and width/height expressions cannot be set at the same time.\n");
139  return AVERROR(EINVAL);
140  }
141 
142  if (s->w_expr && !s->h_expr)
143  FFSWAP(char *, s->w_expr, s->size_str);
144 
145  if (s->size_str) {
146  char buf[32];
147  if ((ret = av_parse_video_size(&s->w, &s->h, s->size_str)) < 0) {
149  "Invalid size '%s'\n", s->size_str);
150  return ret;
151  }
152  snprintf(buf, sizeof(buf)-1, "%d", s->w);
153  av_opt_set(s, "w", buf, 0);
154  snprintf(buf, sizeof(buf)-1, "%d", s->h);
155  av_opt_set(s, "h", buf, 0);
156  }
157  if (!s->w_expr)
158  av_opt_set(s, "w", "iw", 0);
159  if (!s->h_expr)
160  av_opt_set(s, "h", "ih", 0);
161 
162  return 0;
163 }
164 
166 {
167  static const enum AVPixelFormat pixel_fmts[] = {
188  };
189  int ret;
190 
191  ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->outcfg.formats);
192  if (ret < 0)
193  return ret;
194  return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats);
195 }
196 
197 static int config_props(AVFilterLink *outlink)
198 {
199  AVFilterContext *ctx = outlink->src;
200  AVFilterLink *inlink = outlink->src->inputs[0];
201  ZScaleContext *s = ctx->priv;
203  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
204  int64_t w, h;
205  double var_values[VARS_NB], res;
206  char *expr;
207  int ret;
208  int factor_w, factor_h;
209 
210  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
211  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
212  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
213  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
214  var_values[VAR_A] = (double) inlink->w / inlink->h;
215  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
216  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
217  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
218  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
219  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
220  var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
221  var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
222 
223  /* evaluate width and height */
224  av_expr_parse_and_eval(&res, (expr = s->w_expr),
225  var_names, var_values,
226  NULL, NULL, NULL, NULL, NULL, 0, ctx);
227  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
228  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
229  var_names, var_values,
230  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
231  goto fail;
232  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
233  /* evaluate again the width, as it may depend on the output height */
234  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
235  var_names, var_values,
236  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
237  goto fail;
238  s->w = res;
239 
240  w = s->w;
241  h = s->h;
242 
243  /* Check if it is requested that the result has to be divisible by a some
244  * factor (w or h = -n with n being the factor). */
245  factor_w = 1;
246  factor_h = 1;
247  if (w < -1) {
248  factor_w = -w;
249  }
250  if (h < -1) {
251  factor_h = -h;
252  }
253 
254  if (w < 0 && h < 0)
255  s->w = s->h = 0;
256 
257  if (!(w = s->w))
258  w = inlink->w;
259  if (!(h = s->h))
260  h = inlink->h;
261 
262  /* Make sure that the result is divisible by the factor we determined
263  * earlier. If no factor was set, it is nothing will happen as the default
264  * factor is 1 */
265  if (w < 0)
266  w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
267  if (h < 0)
268  h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
269 
270  /* Note that force_original_aspect_ratio may overwrite the previous set
271  * dimensions so that it is not divisible by the set factors anymore. */
272  if (s->force_original_aspect_ratio) {
273  int tmp_w = av_rescale(h, inlink->w, inlink->h);
274  int tmp_h = av_rescale(w, inlink->h, inlink->w);
275 
276  if (s->force_original_aspect_ratio == 1) {
277  w = FFMIN(tmp_w, w);
278  h = FFMIN(tmp_h, h);
279  } else {
280  w = FFMAX(tmp_w, w);
281  h = FFMAX(tmp_h, h);
282  }
283  }
284 
285  if (w > INT_MAX || h > INT_MAX ||
286  (h * inlink->w) > INT_MAX ||
287  (w * inlink->h) > INT_MAX)
288  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
289 
290  outlink->w = w;
291  outlink->h = h;
292 
293  if (inlink->w == outlink->w &&
294  inlink->h == outlink->h &&
295  inlink->format == outlink->format)
296  ;
297  else {
298  }
299 
300  if (inlink->sample_aspect_ratio.num){
301  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
302  } else
303  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
304 
305  av_log(ctx, AV_LOG_TRACE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d\n",
306  inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
307  inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
308  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
309  outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
310  return 0;
311 
312 fail:
314  "Error when evaluating the expression '%s'.\n"
315  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
316  expr, s->w_expr, s->h_expr);
317  return ret;
318 }
319 
321 {
322  char err_msg[1024];
323  int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
324 
325  av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
326 
327  return AVERROR_EXTERNAL;
328 }
329 
330 static int convert_chroma_location(enum AVChromaLocation chroma_location)
331 {
332  switch (chroma_location) {
334  case AVCHROMA_LOC_LEFT:
335  return ZIMG_CHROMA_LEFT;
336  case AVCHROMA_LOC_CENTER:
337  return ZIMG_CHROMA_CENTER;
339  return ZIMG_CHROMA_TOP_LEFT;
340  case AVCHROMA_LOC_TOP:
341  return ZIMG_CHROMA_TOP;
343  return ZIMG_CHROMA_BOTTOM_LEFT;
344  case AVCHROMA_LOC_BOTTOM:
345  return ZIMG_CHROMA_BOTTOM;
346  }
347  return ZIMG_CHROMA_LEFT;
348 }
349 
350 static int convert_matrix(enum AVColorSpace colorspace)
351 {
352  switch (colorspace) {
353  case AVCOL_SPC_RGB:
354  return ZIMG_MATRIX_RGB;
355  case AVCOL_SPC_BT709:
356  return ZIMG_MATRIX_709;
358  return ZIMG_MATRIX_UNSPECIFIED;
359  case AVCOL_SPC_FCC:
360  return ZIMG_MATRIX_FCC;
361  case AVCOL_SPC_BT470BG:
362  return ZIMG_MATRIX_470BG;
363  case AVCOL_SPC_SMPTE170M:
364  return ZIMG_MATRIX_170M;
365  case AVCOL_SPC_SMPTE240M:
366  return ZIMG_MATRIX_240M;
367  case AVCOL_SPC_YCGCO:
368  return ZIMG_MATRIX_YCGCO;
370  return ZIMG_MATRIX_2020_NCL;
371  case AVCOL_SPC_BT2020_CL:
372  return ZIMG_MATRIX_2020_CL;
374  return ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL;
376  return ZIMG_MATRIX_CHROMATICITY_DERIVED_CL;
377  case AVCOL_SPC_ICTCP:
378  return ZIMG_MATRIX_ICTCP;
379  }
380  return ZIMG_MATRIX_UNSPECIFIED;
381 }
382 
383 static int convert_trc(enum AVColorTransferCharacteristic color_trc)
384 {
385  switch (color_trc) {
387  return ZIMG_TRANSFER_UNSPECIFIED;
388  case AVCOL_TRC_BT709:
389  return ZIMG_TRANSFER_709;
390  case AVCOL_TRC_GAMMA22:
391  return ZIMG_TRANSFER_470_M;
392  case AVCOL_TRC_GAMMA28:
393  return ZIMG_TRANSFER_470_BG;
394  case AVCOL_TRC_SMPTE170M:
395  return ZIMG_TRANSFER_601;
396  case AVCOL_TRC_SMPTE240M:
397  return ZIMG_TRANSFER_240M;
398  case AVCOL_TRC_LINEAR:
399  return ZIMG_TRANSFER_LINEAR;
400  case AVCOL_TRC_LOG:
401  return ZIMG_TRANSFER_LOG_100;
402  case AVCOL_TRC_LOG_SQRT:
403  return ZIMG_TRANSFER_LOG_316;
405  return ZIMG_TRANSFER_IEC_61966_2_4;
406  case AVCOL_TRC_BT2020_10:
407  return ZIMG_TRANSFER_2020_10;
408  case AVCOL_TRC_BT2020_12:
409  return ZIMG_TRANSFER_2020_12;
410  case AVCOL_TRC_SMPTE2084:
411  return ZIMG_TRANSFER_ST2084;
413  return ZIMG_TRANSFER_ARIB_B67;
415  return ZIMG_TRANSFER_IEC_61966_2_1;
416  }
417  return ZIMG_TRANSFER_UNSPECIFIED;
418 }
419 
421 {
422  switch (color_primaries) {
424  return ZIMG_PRIMARIES_UNSPECIFIED;
425  case AVCOL_PRI_BT709:
426  return ZIMG_PRIMARIES_709;
427  case AVCOL_PRI_BT470M:
428  return ZIMG_PRIMARIES_470_M;
429  case AVCOL_PRI_BT470BG:
430  return ZIMG_PRIMARIES_470_BG;
431  case AVCOL_PRI_SMPTE170M:
432  return ZIMG_PRIMARIES_170M;
433  case AVCOL_PRI_SMPTE240M:
434  return ZIMG_PRIMARIES_240M;
435  case AVCOL_PRI_FILM:
436  return ZIMG_PRIMARIES_FILM;
437  case AVCOL_PRI_BT2020:
438  return ZIMG_PRIMARIES_2020;
439  case AVCOL_PRI_SMPTE428:
440  return ZIMG_PRIMARIES_ST428;
441  case AVCOL_PRI_SMPTE431:
442  return ZIMG_PRIMARIES_ST431_2;
443  case AVCOL_PRI_SMPTE432:
444  return ZIMG_PRIMARIES_ST432_1;
445  case AVCOL_PRI_JEDEC_P22:
446  return ZIMG_PRIMARIES_EBU3213_E;
447  }
448  return ZIMG_PRIMARIES_UNSPECIFIED;
449 }
450 
452 {
453  switch (color_range) {
455  case AVCOL_RANGE_MPEG:
456  return ZIMG_RANGE_LIMITED;
457  case AVCOL_RANGE_JPEG:
458  return ZIMG_RANGE_FULL;
459  }
460  return ZIMG_RANGE_LIMITED;
461 }
462 
463 static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range)
464 {
465  switch (color_range) {
466  case ZIMG_RANGE_LIMITED:
467  return AVCOL_RANGE_MPEG;
468  case ZIMG_RANGE_FULL:
469  return AVCOL_RANGE_JPEG;
470  }
472 }
473 
474 static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc,
475  int colorspace, int primaries, int transfer, int range, int location)
476 {
477  format->width = frame->width;
478  format->height = frame->height;
479  format->subsample_w = desc->log2_chroma_w;
480  format->subsample_h = desc->log2_chroma_h;
481  format->depth = desc->comp[0].depth;
482  format->pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
483  format->color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
484  format->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : colorspace == -1 ? convert_matrix(frame->colorspace) : colorspace;
485  format->color_primaries = primaries == -1 ? convert_primaries(frame->color_primaries) : primaries;
486  format->transfer_characteristics = transfer == - 1 ? convert_trc(frame->color_trc) : transfer;
487  format->pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : range == -1 ? convert_range(frame->color_range) : range;
488  format->chroma_location = location == -1 ? convert_chroma_location(frame->chroma_location) : location;
489 }
490 
491 static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params,
492  zimg_image_format *src_format, zimg_image_format *dst_format,
493  void **tmp, size_t *tmp_size)
494 {
495  int ret;
496  size_t size;
497 
498  zimg_filter_graph_free(*graph);
499  *graph = zimg_filter_graph_build(src_format, dst_format, params);
500  if (!*graph)
501  return print_zimg_error(NULL);
502 
503  ret = zimg_filter_graph_get_tmp_size(*graph, &size);
504  if (ret)
505  return print_zimg_error(NULL);
506 
507  if (size > *tmp_size) {
508  av_freep(tmp);
509  *tmp = av_malloc(size);
510  if (!*tmp)
511  return AVERROR(ENOMEM);
512 
513  *tmp_size = size;
514  }
515 
516  return 0;
517 }
518 
520 {
521  AVFrame *aligned = NULL;
522  int ret = 0, plane;
523 
524  /* Realign any unaligned input frame. */
525  for (plane = 0; plane < 3; plane++) {
526  int p = desc->comp[plane].plane;
527  if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) {
528  if (!(aligned = av_frame_alloc())) {
529  ret = AVERROR(ENOMEM);
530  goto fail;
531  }
532 
533  aligned->format = (*frame)->format;
534  aligned->width = (*frame)->width;
535  aligned->height = (*frame)->height;
536 
538  goto fail;
539 
540  if ((ret = av_frame_copy(aligned, *frame)) < 0)
541  goto fail;
542 
543  if ((ret = av_frame_copy_props(aligned, *frame)) < 0)
544  goto fail;
545 
547  *frame = aligned;
548  return 0;
549  }
550  }
551 
552 fail:
554  return ret;
555 }
556 
558 {
559  if (s->colorspace != -1)
560  frame->colorspace = (int)s->dst_format.matrix_coefficients;
561 
562  if (s->primaries != -1)
563  frame->color_primaries = (int)s->dst_format.color_primaries;
564 
565  if (s->range != -1)
566  frame->color_range = convert_range_from_zimg(s->dst_format.pixel_range);
567 
568  if (s->trc != -1)
569  frame->color_trc = (int)s->dst_format.transfer_characteristics;
570 
571  if (s->chromal != -1)
572  frame->chroma_location = (int)s->dst_format.chroma_location + 1;
573 }
574 
576 {
577  ZScaleContext *s = link->dst->priv;
578  AVFilterLink *outlink = link->dst->outputs[0];
580  const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
581  zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
582  zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
583  char buf[32];
584  int ret = 0, plane;
585  AVFrame *out = NULL;
586 
587  if ((ret = realign_frame(desc, &in)) < 0)
588  goto fail;
589 
590  if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) {
591  ret = AVERROR(ENOMEM);
592  goto fail;
593  }
594 
596  out->width = outlink->w;
597  out->height = outlink->h;
598 
599  if( in->width != link->w
600  || in->height != link->h
601  || in->format != link->format
602  || s->in_colorspace != in->colorspace
603  || s->in_trc != in->color_trc
604  || s->in_primaries != in->color_primaries
605  || s->in_range != in->color_range
606  || s->out_colorspace != out->colorspace
607  || s->out_trc != out->color_trc
608  || s->out_primaries != out->color_primaries
609  || s->out_range != out->color_range
610  || s->in_chromal != in->chroma_location
611  || s->out_chromal != out->chroma_location) {
612  snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
613  av_opt_set(s, "w", buf, 0);
614  snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
615  av_opt_set(s, "h", buf, 0);
616 
617  link->dst->inputs[0]->format = in->format;
618  link->dst->inputs[0]->w = in->width;
619  link->dst->inputs[0]->h = in->height;
620 
621  if ((ret = config_props(outlink)) < 0)
622  goto fail;
623 
624  zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
625  zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
626  zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
627 
628  s->params.dither_type = s->dither;
629  s->params.cpu_type = ZIMG_CPU_AUTO;
630  s->params.resample_filter = s->filter;
631  s->params.resample_filter_uv = s->filter;
632  s->params.nominal_peak_luminance = s->nominal_peak_luminance;
633  s->params.allow_approximate_gamma = s->approximate_gamma;
634  s->params.filter_param_a = s->params.filter_param_a_uv = s->param_a;
635  s->params.filter_param_b = s->params.filter_param_b_uv = s->param_b;
636 
637  format_init(&s->src_format, in, desc, s->colorspace_in,
638  s->primaries_in, s->trc_in, s->range_in, s->chromal_in);
639  format_init(&s->dst_format, out, odesc, s->colorspace,
640  s->primaries, s->trc, s->range, s->chromal);
641 
643 
644  ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format,
645  &s->tmp, &s->tmp_size);
646  if (ret < 0)
647  goto fail;
648 
649  s->in_colorspace = in->colorspace;
650  s->in_trc = in->color_trc;
651  s->in_primaries = in->color_primaries;
652  s->in_range = in->color_range;
653  s->out_colorspace = out->colorspace;
654  s->out_trc = out->color_trc;
655  s->out_primaries = out->color_primaries;
656  s->out_range = out->color_range;
657 
658  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
659  zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
660  zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
661  zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
662 
663  s->alpha_params.dither_type = s->dither;
664  s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
665  s->alpha_params.resample_filter = s->filter;
666 
667  s->alpha_src_format.width = in->width;
668  s->alpha_src_format.height = in->height;
669  s->alpha_src_format.depth = desc->comp[0].depth;
670  s->alpha_src_format.pixel_type = (desc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
671  s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
672 
673  s->alpha_dst_format.width = out->width;
674  s->alpha_dst_format.height = out->height;
675  s->alpha_dst_format.depth = odesc->comp[0].depth;
676  s->alpha_dst_format.pixel_type = (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) ? ZIMG_PIXEL_FLOAT : odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
677  s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
678 
679  zimg_filter_graph_free(s->alpha_graph);
680  s->alpha_graph = zimg_filter_graph_build(&s->alpha_src_format, &s->alpha_dst_format, &s->alpha_params);
681  if (!s->alpha_graph) {
682  ret = print_zimg_error(link->dst);
683  goto fail;
684  }
685  }
686  }
687 
689 
690  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
691  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
692  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
693  INT_MAX);
694 
695  for (plane = 0; plane < 3; plane++) {
696  int p = desc->comp[plane].plane;
697  src_buf.plane[plane].data = in->data[p];
698  src_buf.plane[plane].stride = in->linesize[p];
699  src_buf.plane[plane].mask = -1;
700 
701  p = odesc->comp[plane].plane;
702  dst_buf.plane[plane].data = out->data[p];
703  dst_buf.plane[plane].stride = out->linesize[p];
704  dst_buf.plane[plane].mask = -1;
705  }
706 
707  ret = zimg_filter_graph_process(s->graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
708  if (ret) {
709  ret = print_zimg_error(link->dst);
710  goto fail;
711  }
712 
713  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
714  src_buf.plane[0].data = in->data[3];
715  src_buf.plane[0].stride = in->linesize[3];
716  src_buf.plane[0].mask = -1;
717 
718  dst_buf.plane[0].data = out->data[3];
719  dst_buf.plane[0].stride = out->linesize[3];
720  dst_buf.plane[0].mask = -1;
721 
722  ret = zimg_filter_graph_process(s->alpha_graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
723  if (ret) {
724  ret = print_zimg_error(link->dst);
725  goto fail;
726  }
727  } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
728  int x, y;
729 
730  if (odesc->flags & AV_PIX_FMT_FLAG_FLOAT) {
731  for (y = 0; y < out->height; y++) {
732  for (x = 0; x < out->width; x++) {
733  AV_WN32(out->data[3] + x * odesc->comp[3].step + y * out->linesize[3],
734  av_float2int(1.0f));
735  }
736  }
737  } else {
738  for (y = 0; y < outlink->h; y++)
739  memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
740  }
741  }
742 
743 fail:
744  av_frame_free(&in);
745  if (ret) {
746  av_frame_free(&out);
747  return ret;
748  }
749 
750  return ff_filter_frame(outlink, out);
751 }
752 
754 {
755  ZScaleContext *s = ctx->priv;
756 
757  zimg_filter_graph_free(s->graph);
758  zimg_filter_graph_free(s->alpha_graph);
759  av_freep(&s->tmp);
760  s->tmp_size = 0;
761 }
762 
763 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
764  char *res, int res_len, int flags)
765 {
766  ZScaleContext *s = ctx->priv;
767  int ret;
768 
769  if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
770  || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
771 
772  int old_w = s->w;
773  int old_h = s->h;
774  AVFilterLink *outlink = ctx->outputs[0];
775 
776  av_opt_set(s, cmd, args, 0);
777  if ((ret = config_props(outlink)) < 0) {
778  s->w = old_w;
779  s->h = old_h;
780  }
781  } else
782  ret = AVERROR(ENOSYS);
783 
784  return ret;
785 }
786 
787 #define OFFSET(x) offsetof(ZScaleContext, x)
788 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
789 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
790 
791 static const AVOption zscale_options[] = {
792  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
793  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
794  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
795  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = TFLAGS },
796  { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
797  { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
798  { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
799  { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
800  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, "dither" },
801  { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, "dither" },
802  { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, "dither" },
803  { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, "dither" },
804  { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
805  { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
806  { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, "filter" },
807  { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, "filter" },
808  { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, "filter" },
809  { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, "filter" },
810  { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, "filter" },
811  { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, "filter" },
812  { "out_range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
813  { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
814  { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
815  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
816  { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
817  { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
818  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
819  { "tv", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
820  { "pc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
821  { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
822  { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
823  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "primaries" },
824  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
825  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
826  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
827  { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
828  { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
829  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
830  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
831  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_M}, 0, 0, FLAGS, "primaries" },
832  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_470_BG}, 0, 0, FLAGS, "primaries" },
833  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
834  { "smpte240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
835  { "film", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_FILM}, 0, 0, FLAGS, "primaries" },
836  { "bt2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
837  { "smpte428", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST428}, 0, 0, FLAGS, "primaries" },
838  { "smpte431", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST431_2}, 0, 0, FLAGS, "primaries" },
839  { "smpte432", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST432_1}, 0, 0, FLAGS, "primaries" },
840  { "jedec-p22", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
841  { "ebu3213", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_EBU3213_E}, 0, 0, FLAGS, "primaries" },
842  { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
843  { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
844  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "transfer" },
845  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
846  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
847  { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
848  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
849  { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
850  { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
851  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
852  { "bt470m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_M}, 0, 0, FLAGS, "transfer" },
853  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_470_BG}, 0, 0, FLAGS, "transfer" },
854  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
855  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
856  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
857  { "log100", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_100}, 0, 0, FLAGS, "transfer" },
858  { "log316", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LOG_316}, 0, 0, FLAGS, "transfer" },
859  { "bt2020-10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
860  { "bt2020-12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
861  { "smpte2084", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ST2084}, 0, 0, FLAGS, "transfer" },
862  { "iec61966-2-4", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_4},0, 0, FLAGS, "transfer" },
863  { "iec61966-2-1", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0, FLAGS, "transfer" },
864  { "arib-std-b67", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ARIB_B67}, 0, 0, FLAGS, "transfer" },
865  { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
866  { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
867  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "matrix" },
868  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
869  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
870  { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
871  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
872  { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
873  { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
874  { "unknown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
875  { "gbr", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_RGB}, 0, 0, FLAGS, "matrix" },
876  { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
877  { "fcc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_FCC}, 0, 0, FLAGS, "matrix" },
878  { "bt470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
879  { "smpte170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
880  { "smpte2400m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_240M}, 0, 0, FLAGS, "matrix" },
881  { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, "matrix" },
882  { "bt2020nc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
883  { "bt2020c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
884  { "chroma-derived-nc",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_NCL}, 0, 0, FLAGS, "matrix" },
885  { "chroma-derived-c", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_CHROMATICITY_DERIVED_CL}, 0, 0, FLAGS, "matrix" },
886  { "ictcp", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_ICTCP}, 0, 0, FLAGS, "matrix" },
887  { "in_range", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
888  { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
889  { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
890  { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
891  { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "primaries" },
892  { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
893  { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "transfer" },
894  { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
895  { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, "matrix" },
896  { "chromal", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
897  { "c", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
898  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "chroma" },
899  { "left", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_LEFT}, 0, 0, FLAGS, "chroma" },
900  { "center", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_CENTER}, 0, 0, FLAGS, "chroma" },
901  { "topleft", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP_LEFT}, 0, 0, FLAGS, "chroma" },
902  { "top", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP}, 0, 0, FLAGS, "chroma" },
903  { "bottomleft",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM_LEFT}, 0, 0, FLAGS, "chroma" },
904  { "bottom", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM}, 0, 0, FLAGS, "chroma" },
905  { "chromalin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
906  { "cin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
907  { "npl", "set nominal peak luminance", OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, FLAGS },
908  { "agamma", "allow approximate gamma", OFFSET(approximate_gamma), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
909  { "param_a", "parameter A, which is parameter \"b\" for bicubic, "
910  "and the number of filter taps for lanczos", OFFSET(param_a), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
911  { "param_b", "parameter B, which is parameter \"c\" for bicubic", OFFSET(param_b), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, -DBL_MAX, DBL_MAX, FLAGS },
912  { NULL }
913 };
914 
915 AVFILTER_DEFINE_CLASS(zscale);
916 
918  {
919  .name = "default",
920  .type = AVMEDIA_TYPE_VIDEO,
921  .filter_frame = filter_frame,
922  },
923 };
924 
926  {
927  .name = "default",
928  .type = AVMEDIA_TYPE_VIDEO,
929  .config_props = config_props,
930  },
931 };
932 
934  .name = "zscale",
935  .description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
936  .init = init,
937  .priv_size = sizeof(ZScaleContext),
938  .priv_class = &zscale_class,
939  .uninit = uninit,
943  .process_command = process_command,
944 };
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:98
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:447
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:570
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:426
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:566
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ZScaleContext::range_in
int range_in
Definition: vf_zscale.c:98
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:381
ZScaleContext::colorspace_in
int colorspace_in
Definition: vf_zscale.c:95
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:494
convert_range_from_zimg
static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range)
Definition: vf_zscale.c:463
out
FILE * out
Definition: movenc.c:54
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:243
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_zscale.c:753
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2660
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:503
AVCHROMA_LOC_BOTTOM
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:623
ZScaleContext::h_expr
char * h_expr
height expression string
Definition: vf_zscale.c:107
ZScaleContext::filter
int filter
Definition: vf_zscale.c:89
ZIMG_ALIGNMENT
#define ZIMG_ALIGNMENT
Definition: vf_zscale.c:46
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_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:158
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:568
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:439
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:577
ZScaleContext::chromal
int chromal
Definition: vf_zscale.c:94
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
VAR_VSUB
@ VAR_VSUB
Definition: vf_zscale.c:72
pixdesc.h
TFLAGS
#define TFLAGS
Definition: vf_zscale.c:789
var_names
static const char *const var_names[]
Definition: vf_zscale.c:48
AVFrame::width
int width
Definition: frame.h:389
config_props
static int config_props(AVFilterLink *outlink)
Definition: vf_zscale.c:197
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:446
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:597
ZScaleContext::colorspace
int colorspace
Definition: vf_zscale.c:90
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:441
ZScaleContext::alpha_src_format
zimg_image_format alpha_src_format
Definition: vf_zscale.c:120
AVOption
AVOption.
Definition: opt.h:247
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:497
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
AVComponentDescriptor::step
int step
Number of elements between 2 horizontally consecutive pixels.
Definition: pixdesc.h:40
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:404
AVCOL_PRI_JEDEC_P22
@ AVCOL_PRI_JEDEC_P22
Definition: pixfmt.h:486
format_init
static void format_init(zimg_image_format *format, AVFrame *frame, const AVPixFmtDescriptor *desc, int colorspace, int primaries, int transfer, int range, int location)
Definition: vf_zscale.c:474
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:524
float.h
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:510
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_amplify.c:53
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
mathematics.h
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
zscale_options
static const AVOption zscale_options[]
Definition: vf_zscale.c:791
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:469
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
graph_build
static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *params, zimg_image_format *src_format, zimg_image_format *dst_format, void **tmp, size_t *tmp_size)
Definition: vf_zscale.c:491
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:442
ZScaleContext::h
int h
Definition: vf_zscale.c:87
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:535
ZScaleContext::out_chromal
enum AVChromaLocation in_chromal out_chromal
Definition: vf_zscale.c:128
ZScaleContext::primaries
int primaries
Definition: vf_zscale.c:92
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:338
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ZScaleContext::in_h_chr_pos
int in_h_chr_pos
Definition: vf_zscale.c:111
formats.h
ZScaleContext::param_b
double param_b
Definition: vf_zscale.c:104
VAR_OUT_W
@ VAR_OUT_W
Definition: vf_zscale.c:66
AVFrame::chroma_location
enum AVChromaLocation chroma_location
Definition: frame.h:579
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:529
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:438
convert_primaries
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition: vf_zscale.c:420
ZScaleContext::dst_format
zimg_image_format dst_format
Definition: vf_zscale.c:119
graph
ofilter graph
Definition: ffmpeg_filter.c:171
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:422
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:508
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
ZScaleContext::src_format
zimg_image_format src_format
Definition: vf_zscale.c:119
fail
#define fail()
Definition: checkasm.h:127
ZScaleContext::out_primaries
enum AVColorPrimaries in_primaries out_primaries
Definition: vf_zscale.c:126
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:420
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:448
ZScaleContext::range
int range
Definition: vf_zscale.c:93
VAR_OW
@ VAR_OW
Definition: vf_zscale.c:66
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:402
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:500
convert_matrix
static int convert_matrix(enum AVColorSpace colorspace)
Definition: vf_zscale.c:350
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_zscale.c:165
ZScaleContext::alpha_params
zimg_graph_builder_params alpha_params
Definition: vf_zscale.c:121
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:468
AVCOL_TRC_LOG_SQRT
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
Definition: pixfmt.h:505
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:499
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_zscale.c:763
VAR_SAR
@ VAR_SAR
Definition: vf_zscale.c:69
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:97
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:407
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:248
aligned
static int aligned(int val)
Definition: dashdec.c:169
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ZScaleContext::alpha_graph
zimg_filter_graph * alpha_graph
Definition: vf_zscale.c:122
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:416
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
ZScaleContext::param_a
double param_a
Definition: vf_zscale.c:103
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:621
ZScaleContext
Definition: vf_zscale.c:78
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:417
ZScaleContext::force_original_aspect_ratio
int force_original_aspect_ratio
Definition: vf_zscale.c:114
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:530
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:555
var_name
var_name
Definition: noise_bsf.c:47
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:401
realign_frame
static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame)
Definition: vf_zscale.c:519
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:415
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVCOL_PRI_SMPTE428
@ AVCOL_PRI_SMPTE428
SMPTE ST 428-1 (CIE 1931 XYZ)
Definition: pixfmt.h:481
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
VAR_A
@ VAR_A
Definition: vf_zscale.c:68
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVCOL_PRI_SMPTE240M
@ AVCOL_PRI_SMPTE240M
identical to above, also called "SMPTE C" even though it uses D65
Definition: pixfmt.h:478
color_range
color_range
Definition: vf_selectivecolor.c:44
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:472
NAN
#define NAN
Definition: mathematics.h:64
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
AVCOL_SPC_CHROMA_DERIVED_CL
@ AVCOL_SPC_CHROMA_DERIVED_CL
Chromaticity-derived constant luminance system.
Definition: pixfmt.h:538
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:476
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:477
if
if(ret)
Definition: filter_design.txt:179
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:423
ZScaleContext::params
zimg_graph_builder_params params
Definition: vf_zscale.c:121
print_zimg_error
static int print_zimg_error(AVFilterContext *ctx)
Definition: vf_zscale.c:320
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
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:537
ZScaleContext::out_range
enum AVColorRange in_range out_range
Definition: vf_zscale.c:127
FLAGS
#define FLAGS
Definition: vf_zscale.c:788
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:618
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:620
AVCOL_TRC_IEC61966_2_4
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:506
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:410
AVComponentDescriptor::plane
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:34
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:471
parseutils.h
convert_range
static int convert_range(enum AVColorRange color_range)
Definition: vf_zscale.c:451
ZScaleContext::out_v_chr_pos
int out_v_chr_pos
Definition: vf_zscale.c:110
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:509
AVCOL_SPC_YCGCO
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
Definition: pixfmt.h:532
ZScaleContext::dither
int dither
Definition: vf_zscale.c:88
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:405
update_output_color_information
static void update_output_color_information(ZScaleContext *s, AVFrame *frame)
Definition: vf_zscale.c:557
ff_vf_zscale
const AVFilter ff_vf_zscale
Definition: vf_zscale.c:933
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:419
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:563
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:480
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:511
AVCOL_PRI_SMPTE431
@ AVCOL_PRI_SMPTE431
SMPTE ST 431-2 (2011) / DCI P3.
Definition: pixfmt.h:483
ZScaleContext::in_v_chr_pos
int in_v_chr_pos
Definition: vf_zscale.c:112
eval.h
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:117
av_expr_parse_and_eval
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:776
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:502
AVCOL_PRI_FILM
@ AVCOL_PRI_FILM
colour filters using Illuminant C
Definition: pixfmt.h:479
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:678
AVCOL_TRC_LOG
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
Definition: pixfmt.h:504
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:433
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:409
size
int size
Definition: twinvq_data.h:10344
ZScaleContext::primaries_in
int primaries_in
Definition: vf_zscale.c:97
ZScaleContext::approximate_gamma
int approximate_gamma
Definition: vf_zscale.c:102
ZScaleContext::alpha_dst_format
zimg_image_format alpha_dst_format
Definition: vf_zscale.c:120
VAR_OHSUB
@ VAR_OHSUB
Definition: vf_zscale.c:73
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:411
format
ofilter format
Definition: ffmpeg_filter.c:172
ZScaleContext::graph
zimg_filter_graph * graph
Definition: vf_zscale.c:122
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:617
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:404
VAR_IN_W
@ VAR_IN_W
Definition: vf_zscale.c:64
avfilter_vf_zscale_outputs
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition: vf_zscale.c:925
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:443
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
VARS_NB
@ VARS_NB
Definition: vf_zscale.c:75
AVCOL_SPC_CHROMA_DERIVED_NCL
@ AVCOL_SPC_CHROMA_DERIVED_NCL
Chromaticity-derived non-constant luminance system.
Definition: pixfmt.h:537
VAR_HSUB
@ VAR_HSUB
Definition: vf_zscale.c:71
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:496
internal.h
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:616
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:531
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:534
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_zscale.c:575
internal.h
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:421
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:523
ZScaleContext::tmp_size
size_t tmp_size
Definition: vf_zscale.c:117
ZScaleContext::out_colorspace
enum AVColorSpace in_colorspace out_colorspace
Definition: vf_zscale.c:124
VAR_IW
@ VAR_IW
Definition: vf_zscale.c:64
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ZScaleContext::w
int w
New dimensions.
Definition: vf_zscale.c:87
ZScaleContext::trc
int trc
Definition: vf_zscale.c:91
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
VAR_OH
@ VAR_OH
Definition: vf_zscale.c:67
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:526
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:128
ZScaleContext::chromal_in
int chromal_in
Definition: vf_zscale.c:99
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:580
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:403
AVFilter
Filter definition.
Definition: avfilter.h:165
VAR_IH
@ VAR_IH
Definition: vf_zscale.c:65
AVCOL_PRI_BT470M
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:474
ret
ret
Definition: filter_design.txt:187
ZScaleContext::trc_in
int trc_in
Definition: vf_zscale.c:96
ZScaleContext::size_str
char * size_str
Definition: vf_zscale.c:100
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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:264
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:440
convert_chroma_location
static int convert_chroma_location(enum AVChromaLocation chroma_location)
Definition: vf_zscale.c:330
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:419
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:408
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:413
AVFrame::height
int height
Definition: frame.h:389
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:515
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_zscale.c:131
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:619
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCOL_SPC_FCC
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:528
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:434
VAR_IN_H
@ VAR_IN_H
Definition: vf_zscale.c:65
VAR_OVSUB
@ VAR_OVSUB
Definition: vf_zscale.c:74
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
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:501
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
OFFSET
#define OFFSET(x)
Definition: vf_zscale.c:787
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
convert_trc
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
Definition: vf_zscale.c:383
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVCOL_PRI_SMPTE432
@ AVCOL_PRI_SMPTE432
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:484
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
VAR_DAR
@ VAR_DAR
Definition: vf_zscale.c:70
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:362
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(zscale)
ZScaleContext::nominal_peak_luminance
double nominal_peak_luminance
Definition: vf_zscale.c:101
ZScaleContext::out_trc
enum AVColorTransferCharacteristic in_trc out_trc
Definition: vf_zscale.c:125
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:414
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
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:525
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:562
int
int
Definition: ffmpeg_filter.c:153
AVCOL_SPC_ICTCP
@ AVCOL_SPC_ICTCP
ITU-R BT.2100-0, ICtCp.
Definition: pixfmt.h:539
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
snprintf
#define snprintf
Definition: snprintf.h:34
VAR_OUT_H
@ VAR_OUT_H
Definition: vf_zscale.c:67
color_primaries
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
Definition: vf_colorspace.c:211
ZScaleContext::out_h_chr_pos
int out_h_chr_pos
Definition: vf_zscale.c:109
AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:622
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
ZScaleContext::tmp
void * tmp
Definition: vf_zscale.c:116
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:166
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:412
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2580
ZScaleContext::w_expr
char * w_expr
width expression string
Definition: vf_zscale.c:106
avfilter_vf_zscale_inputs
static const AVFilterPad avfilter_vf_zscale_inputs[]
Definition: vf_zscale.c:917
dither
static const uint8_t dither[8][8]
Definition: vf_fspp.c:58