FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/mathematics.h"
40 #include "libavutil/opt.h"
41 #include "libavutil/parseutils.h"
42 #include "libavutil/pixdesc.h"
43 #include "libavutil/imgutils.h"
44 #include "libavutil/avassert.h"
45 
46 static const char *const var_names[] = {
47  "in_w", "iw",
48  "in_h", "ih",
49  "out_w", "ow",
50  "out_h", "oh",
51  "a",
52  "sar",
53  "dar",
54  "hsub",
55  "vsub",
56  "ohsub",
57  "ovsub",
58  NULL
59 };
60 
61 enum var_name {
74 };
75 
76 typedef struct ZScaleContext {
77  const AVClass *class;
78 
79  /**
80  * New dimensions. Special values are:
81  * 0 = original width/height
82  * -1 = keep original aspect
83  * -N = try to keep aspect but make sure it is divisible by N
84  */
85  int w, h;
86  int dither;
87  int filter;
89  int trc;
90  int primaries;
91  int range;
92  int chromal;
94  int trc_in;
96  int range_in;
98  char *size_str;
101 
102  char *w_expr; ///< width expression string
103  char *h_expr; ///< height expression string
104 
109 
111 
112  void *tmp;
113  size_t tmp_size;
114 
115  zimg_image_format src_format, dst_format;
116  zimg_image_format alpha_src_format, alpha_dst_format;
117  zimg_graph_builder_params alpha_params, params;
118  zimg_filter_graph *alpha_graph, *graph;
119 
120  enum AVColorSpace in_colorspace, out_colorspace;
122  enum AVColorPrimaries in_primaries, out_primaries;
123  enum AVColorRange in_range, out_range;
124  enum AVChromaLocation in_chromal, out_chromal;
125 } ZScaleContext;
126 
128 {
129  ZScaleContext *s = ctx->priv;
130  int ret;
131 
132  if (s->size_str && (s->w_expr || s->h_expr)) {
133  av_log(ctx, AV_LOG_ERROR,
134  "Size and width/height expressions cannot be set at the same time.\n");
135  return AVERROR(EINVAL);
136  }
137 
138  if (s->w_expr && !s->h_expr)
139  FFSWAP(char *, s->w_expr, s->size_str);
140 
141  if (s->size_str) {
142  char buf[32];
143  if ((ret = av_parse_video_size(&s->w, &s->h, s->size_str)) < 0) {
144  av_log(ctx, AV_LOG_ERROR,
145  "Invalid size '%s'\n", s->size_str);
146  return ret;
147  }
148  snprintf(buf, sizeof(buf)-1, "%d", s->w);
149  av_opt_set(s, "w", buf, 0);
150  snprintf(buf, sizeof(buf)-1, "%d", s->h);
151  av_opt_set(s, "h", buf, 0);
152  }
153  if (!s->w_expr)
154  av_opt_set(s, "w", "iw", 0);
155  if (!s->h_expr)
156  av_opt_set(s, "h", "ih", 0);
157 
158  return 0;
159 }
160 
162 {
163  static const enum AVPixelFormat pixel_fmts[] = {
183  };
184  int ret;
185 
186  ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->out_formats);
187  if (ret < 0)
188  return ret;
189  return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->in_formats);
190 }
191 
192 static int config_props(AVFilterLink *outlink)
193 {
194  AVFilterContext *ctx = outlink->src;
195  AVFilterLink *inlink = outlink->src->inputs[0];
196  ZScaleContext *s = ctx->priv;
198  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
199  int64_t w, h;
200  double var_values[VARS_NB], res;
201  char *expr;
202  int ret;
203  int factor_w, factor_h;
204 
205  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
206  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
207  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
208  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
209  var_values[VAR_A] = (double) inlink->w / inlink->h;
210  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
211  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
212  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
213  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
214  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
215  var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
216  var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
217 
218  /* evaluate width and height */
219  av_expr_parse_and_eval(&res, (expr = s->w_expr),
220  var_names, var_values,
221  NULL, NULL, NULL, NULL, NULL, 0, ctx);
222  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
223  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
224  var_names, var_values,
225  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
226  goto fail;
227  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
228  /* evaluate again the width, as it may depend on the output height */
229  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
230  var_names, var_values,
231  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
232  goto fail;
233  s->w = res;
234 
235  w = s->w;
236  h = s->h;
237 
238  /* Check if it is requested that the result has to be divisible by a some
239  * factor (w or h = -n with n being the factor). */
240  factor_w = 1;
241  factor_h = 1;
242  if (w < -1) {
243  factor_w = -w;
244  }
245  if (h < -1) {
246  factor_h = -h;
247  }
248 
249  if (w < 0 && h < 0)
250  s->w = s->h = 0;
251 
252  if (!(w = s->w))
253  w = inlink->w;
254  if (!(h = s->h))
255  h = inlink->h;
256 
257  /* Make sure that the result is divisible by the factor we determined
258  * earlier. If no factor was set, it is nothing will happen as the default
259  * factor is 1 */
260  if (w < 0)
261  w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
262  if (h < 0)
263  h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
264 
265  /* Note that force_original_aspect_ratio may overwrite the previous set
266  * dimensions so that it is not divisible by the set factors anymore. */
268  int tmp_w = av_rescale(h, inlink->w, inlink->h);
269  int tmp_h = av_rescale(w, inlink->h, inlink->w);
270 
271  if (s->force_original_aspect_ratio == 1) {
272  w = FFMIN(tmp_w, w);
273  h = FFMIN(tmp_h, h);
274  } else {
275  w = FFMAX(tmp_w, w);
276  h = FFMAX(tmp_h, h);
277  }
278  }
279 
280  if (w > INT_MAX || h > INT_MAX ||
281  (h * inlink->w) > INT_MAX ||
282  (w * inlink->h) > INT_MAX)
283  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
284 
285  outlink->w = w;
286  outlink->h = h;
287 
288  if (inlink->w == outlink->w &&
289  inlink->h == outlink->h &&
290  inlink->format == outlink->format)
291  ;
292  else {
293  }
294 
295  if (inlink->sample_aspect_ratio.num){
296  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
297  } else
298  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
299 
300  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d\n",
301  inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
303  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
304  outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
305  return 0;
306 
307 fail:
308  av_log(ctx, AV_LOG_ERROR,
309  "Error when evaluating the expression '%s'.\n"
310  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
311  expr, s->w_expr, s->h_expr);
312  return ret;
313 }
314 
316 {
317  char err_msg[1024];
318  int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
319 
320  av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
321 
322  return err_code;
323 }
324 
325 static int convert_chroma_location(enum AVChromaLocation chroma_location)
326 {
327  switch (chroma_location) {
329  case AVCHROMA_LOC_LEFT:
330  return ZIMG_CHROMA_LEFT;
331  case AVCHROMA_LOC_CENTER:
332  return ZIMG_CHROMA_CENTER;
334  return ZIMG_CHROMA_TOP_LEFT;
335  case AVCHROMA_LOC_TOP:
336  return ZIMG_CHROMA_TOP;
338  return ZIMG_CHROMA_BOTTOM_LEFT;
339  case AVCHROMA_LOC_BOTTOM:
340  return ZIMG_CHROMA_BOTTOM;
341  }
342  return ZIMG_CHROMA_LEFT;
343 }
344 
345 static int convert_matrix(enum AVColorSpace colorspace)
346 {
347  switch (colorspace) {
348  case AVCOL_SPC_RGB:
349  return ZIMG_MATRIX_RGB;
350  case AVCOL_SPC_BT709:
351  return ZIMG_MATRIX_709;
353  return ZIMG_MATRIX_UNSPECIFIED;
354  case AVCOL_SPC_BT470BG:
355  return ZIMG_MATRIX_470BG;
356  case AVCOL_SPC_SMPTE170M:
357  return ZIMG_MATRIX_170M;
358  case AVCOL_SPC_YCGCO:
359  return ZIMG_MATRIX_YCGCO;
361  return ZIMG_MATRIX_2020_NCL;
362  case AVCOL_SPC_BT2020_CL:
363  return ZIMG_MATRIX_2020_CL;
364  }
365  return ZIMG_MATRIX_UNSPECIFIED;
366 }
367 
368 static int convert_trc(enum AVColorTransferCharacteristic color_trc)
369 {
370  switch (color_trc) {
372  return ZIMG_TRANSFER_UNSPECIFIED;
373  case AVCOL_TRC_BT709:
374  return ZIMG_TRANSFER_709;
375  case AVCOL_TRC_SMPTE170M:
376  return ZIMG_TRANSFER_601;
377  case AVCOL_TRC_LINEAR:
378  return ZIMG_TRANSFER_LINEAR;
379  case AVCOL_TRC_BT2020_10:
380  return ZIMG_TRANSFER_2020_10;
381  case AVCOL_TRC_BT2020_12:
382  return ZIMG_TRANSFER_2020_12;
383  case AVCOL_TRC_SMPTE2084:
384  return ZIMG_TRANSFER_ST2084;
386  return ZIMG_TRANSFER_ARIB_B67;
388  return ZIMG_TRANSFER_IEC_61966_2_1;
389  }
390  return ZIMG_TRANSFER_UNSPECIFIED;
391 }
392 
394 {
395  switch (color_primaries) {
397  return ZIMG_PRIMARIES_UNSPECIFIED;
398  case AVCOL_PRI_BT709:
399  return ZIMG_PRIMARIES_709;
400  case AVCOL_PRI_SMPTE170M:
401  return ZIMG_PRIMARIES_170M;
402  case AVCOL_PRI_SMPTE240M:
403  return ZIMG_PRIMARIES_240M;
404  case AVCOL_PRI_BT2020:
405  return ZIMG_PRIMARIES_2020;
406  case AVCOL_PRI_SMPTE432:
407  return ZIMG_PRIMARIES_ST432_1;
408  }
409  return ZIMG_PRIMARIES_UNSPECIFIED;
410 }
411 
413 {
414  switch (color_range) {
416  case AVCOL_RANGE_MPEG:
417  return ZIMG_RANGE_LIMITED;
418  case AVCOL_RANGE_JPEG:
419  return ZIMG_RANGE_FULL;
420  }
421  return ZIMG_RANGE_LIMITED;
422 }
423 
424 static int filter_frame(AVFilterLink *link, AVFrame *in)
425 {
426  ZScaleContext *s = link->dst->priv;
427  AVFilterLink *outlink = link->dst->outputs[0];
429  const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
430  zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
431  zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
432  char buf[32];
433  size_t tmp_size;
434  int ret = 0, plane;
435  AVFrame *out;
436 
437  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
438  if (!out) {
439  av_frame_free(&in);
440  return AVERROR(ENOMEM);
441  }
442 
443  av_frame_copy_props(out, in);
444  out->width = outlink->w;
445  out->height = outlink->h;
446 
447  if( in->width != link->w
448  || in->height != link->h
449  || in->format != link->format
450  || s->in_colorspace != in->colorspace
451  || s->in_trc != in->color_trc
452  || s->in_primaries != in->color_primaries
453  || s->in_range != in->color_range
454  || s->out_colorspace != out->colorspace
455  || s->out_trc != out->color_trc
456  || s->out_primaries != out->color_primaries
457  || s->out_range != out->color_range
458  || s->in_chromal != in->chroma_location
459  || s->out_chromal != out->chroma_location) {
460  snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
461  av_opt_set(s, "w", buf, 0);
462  snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
463  av_opt_set(s, "h", buf, 0);
464 
465  link->dst->inputs[0]->format = in->format;
466  link->dst->inputs[0]->w = in->width;
467  link->dst->inputs[0]->h = in->height;
468 
469  if ((ret = config_props(outlink)) < 0) {
470  av_frame_free(&in);
471  av_frame_free(&out);
472  return ret;
473  }
474 
475  zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
476  zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
477  zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
478 
479  s->params.dither_type = s->dither;
480  s->params.cpu_type = ZIMG_CPU_AUTO;
481  s->params.resample_filter = s->filter;
482  s->params.resample_filter_uv = s->filter;
483  s->params.nominal_peak_luminance = s->nominal_peak_luminance;
484  s->params.allow_approximate_gamma = s->approximate_gamma;
485 
486  s->src_format.width = in->width;
487  s->src_format.height = in->height;
488  s->src_format.subsample_w = desc->log2_chroma_w;
489  s->src_format.subsample_h = desc->log2_chroma_h;
490  s->src_format.depth = desc->comp[0].depth;
491  s->src_format.pixel_type = desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
492  s->src_format.color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
493  s->src_format.matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : s->colorspace_in == -1 ? convert_matrix(in->colorspace) : s->colorspace_in;
494  s->src_format.transfer_characteristics = s->trc_in == - 1 ? convert_trc(in->color_trc) : s->trc_in;
495  s->src_format.color_primaries = s->primaries_in == -1 ? convert_primaries(in->color_primaries) : s->primaries_in;
496  s->src_format.pixel_range = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : s->range_in == -1 ? convert_range(in->color_range) : s->range_in;
497  s->src_format.chroma_location = s->chromal_in == -1 ? convert_chroma_location(in->chroma_location) : s->chromal_in;
498 
499  s->dst_format.width = out->width;
500  s->dst_format.height = out->height;
501  s->dst_format.subsample_w = odesc->log2_chroma_w;
502  s->dst_format.subsample_h = odesc->log2_chroma_h;
503  s->dst_format.depth = odesc->comp[0].depth;
504  s->dst_format.pixel_type = odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
505  s->dst_format.color_family = (odesc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
506  s->dst_format.matrix_coefficients = (odesc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : s->colorspace == -1 ? convert_matrix(out->colorspace) : s->colorspace;
507  s->dst_format.transfer_characteristics = s->trc == -1 ? convert_trc(out->color_trc) : s->trc;
508  s->dst_format.color_primaries = s->primaries == -1 ? convert_primaries(out->color_primaries) : s->primaries;
509  s->dst_format.pixel_range = (odesc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_RANGE_FULL : s->range == -1 ? convert_range(out->color_range) : s->range;
510  s->dst_format.chroma_location = s->chromal == -1 ? convert_chroma_location(out->chroma_location) : s->chromal;
511 
512  if (s->colorspace != -1)
513  out->colorspace = (int)s->dst_format.matrix_coefficients;
514 
515  if (s->primaries != -1)
516  out->color_primaries = (int)s->dst_format.color_primaries;
517 
518  if (s->range != -1)
519  out->color_range = (int)s->dst_format.pixel_range + 1;
520 
521  if (s->trc != -1)
522  out->color_trc = (int)s->dst_format.transfer_characteristics;
523 
524  if (s->chromal != -1)
525  out->chroma_location = (int)s->dst_format.chroma_location - 1;
526 
527  zimg_filter_graph_free(s->graph);
528  s->graph = zimg_filter_graph_build(&s->src_format, &s->dst_format, &s->params);
529  if (!s->graph) {
530  ret = print_zimg_error(link->dst);
531  goto fail;
532  }
533 
534  if ((ret = zimg_filter_graph_get_tmp_size(s->graph, &tmp_size))) {
535  ret = print_zimg_error(link->dst);
536  goto fail;
537  }
538 
539  if (tmp_size > s->tmp_size) {
540  av_freep(&s->tmp);
541  s->tmp = av_malloc(tmp_size);
542  if (!s->tmp) {
543  ret = AVERROR(ENOMEM);
544  goto fail;
545  }
546  s->tmp_size = tmp_size;
547  }
548 
549  s->in_colorspace = in->colorspace;
550  s->in_trc = in->color_trc;
551  s->in_primaries = in->color_primaries;
552  s->in_range = in->color_range;
553  s->out_colorspace = out->colorspace;
554  s->out_trc = out->color_trc;
555  s->out_primaries = out->color_primaries;
556  s->out_range = out->color_range;
557 
558  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
559  zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
560  zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
561  zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
562 
563  s->alpha_params.dither_type = s->dither;
564  s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
565  s->alpha_params.resample_filter = s->filter;
566 
567  s->alpha_src_format.width = in->width;
568  s->alpha_src_format.height = in->height;
569  s->alpha_src_format.depth = desc->comp[0].depth;
570  s->alpha_src_format.pixel_type = desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
571  s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
572 
573  s->alpha_dst_format.width = out->width;
574  s->alpha_dst_format.height = out->height;
575  s->alpha_dst_format.depth = odesc->comp[0].depth;
576  s->alpha_dst_format.pixel_type = odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
577  s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
578 
579  zimg_filter_graph_free(s->alpha_graph);
580  s->alpha_graph = zimg_filter_graph_build(&s->alpha_src_format, &s->alpha_dst_format, &s->alpha_params);
581  if (!s->alpha_graph) {
582  ret = print_zimg_error(link->dst);
583  goto fail;
584  }
585  }
586  }
587 
588  if (s->colorspace != -1)
589  out->colorspace = (int)s->dst_format.matrix_coefficients;
590 
591  if (s->primaries != -1)
592  out->color_primaries = (int)s->dst_format.color_primaries;
593 
594  if (s->range != -1)
595  out->color_range = (int)s->dst_format.pixel_range;
596 
597  if (s->trc != -1)
598  out->color_trc = (int)s->dst_format.transfer_characteristics;
599 
601  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
602  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
603  INT_MAX);
604 
605  for (plane = 0; plane < 3; plane++) {
606  int p = desc->comp[plane].plane;
607  src_buf.plane[plane].data = in->data[p];
608  src_buf.plane[plane].stride = in->linesize[p];
609  src_buf.plane[plane].mask = -1;
610 
611  p = odesc->comp[plane].plane;
612  dst_buf.plane[plane].data = out->data[p];
613  dst_buf.plane[plane].stride = out->linesize[p];
614  dst_buf.plane[plane].mask = -1;
615  }
616 
617  ret = zimg_filter_graph_process(s->graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
618  if (ret) {
619  print_zimg_error(link->dst);
620  goto fail;
621  }
622 
623  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
624  src_buf.plane[0].data = in->data[3];
625  src_buf.plane[0].stride = in->linesize[3];
626  src_buf.plane[0].mask = -1;
627 
628  dst_buf.plane[0].data = out->data[3];
629  dst_buf.plane[0].stride = out->linesize[3];
630  dst_buf.plane[0].mask = -1;
631 
632  ret = zimg_filter_graph_process(s->alpha_graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
633  if (ret) {
634  print_zimg_error(link->dst);
635  goto fail;
636  }
637  } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
638  int y;
639 
640  for (y = 0; y < outlink->h; y++)
641  memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
642  }
643 
644 fail:
645  av_frame_free(&in);
646  if (ret) {
647  av_frame_free(&out);
648  return ret;
649  }
650 
651  return ff_filter_frame(outlink, out);
652 }
653 
655 {
656  ZScaleContext *s = ctx->priv;
657 
658  zimg_filter_graph_free(s->graph);
659  av_freep(&s->tmp);
660  s->tmp_size = 0;
661 }
662 
663 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
664  char *res, int res_len, int flags)
665 {
666  ZScaleContext *s = ctx->priv;
667  int ret;
668 
669  if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
670  || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
671 
672  int old_w = s->w;
673  int old_h = s->h;
674  AVFilterLink *outlink = ctx->outputs[0];
675 
676  av_opt_set(s, cmd, args, 0);
677  if ((ret = config_props(outlink)) < 0) {
678  s->w = old_w;
679  s->h = old_h;
680  }
681  } else
682  ret = AVERROR(ENOSYS);
683 
684  return ret;
685 }
686 
687 #define OFFSET(x) offsetof(ZScaleContext, x)
688 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
689 
690 static const AVOption zscale_options[] = {
691  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
692  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
693  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
694  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
695  { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
696  { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
697  { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
698  { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
699  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, "dither" },
700  { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, "dither" },
701  { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, "dither" },
702  { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, "dither" },
703  { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
704  { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
705  { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, "filter" },
706  { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, "filter" },
707  { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, "filter" },
708  { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, "filter" },
709  { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, "filter" },
710  { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, "filter" },
711  { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
712  { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
713  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
714  { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
715  { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
716  { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_ST432_1, FLAGS, "primaries" },
717  { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_ST432_1, FLAGS, "primaries" },
718  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "primaries" },
719  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
720  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
721  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
722  { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
723  { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
724  { "smpte432", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_ST432_1}, 0, 0, FLAGS, "primaries" },
725  { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_ARIB_B67, FLAGS, "transfer" },
726  { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_ARIB_B67, FLAGS, "transfer" },
727  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "transfer" },
728  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
729  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
730  { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
731  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
732  { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
733  { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
734  { "smpte2084", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ST2084}, 0, 0, FLAGS, "transfer" },
735  { "iec61966-2-1", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_IEC_61966_2_1},0, 0, FLAGS, "transfer" },
736  { "arib-std-b67", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_ARIB_B67}, 0, 0, FLAGS, "transfer" },
737  { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
738  { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
739  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "matrix" },
740  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
741  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
742  { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
743  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
744  { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, "matrix" },
745  { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
746  { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
747  { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
748  { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
749  { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_ST432_1, FLAGS, "primaries" },
750  { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_ST432_1, FLAGS, "primaries" },
751  { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_ARIB_B67, FLAGS, "transfer" },
752  { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_ARIB_B67, FLAGS, "transfer" },
753  { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
754  { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
755  { "chromal", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
756  { "c", "set output chroma location", OFFSET(chromal), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
757  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "chroma" },
758  { "left", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_LEFT}, 0, 0, FLAGS, "chroma" },
759  { "center", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_CENTER}, 0, 0, FLAGS, "chroma" },
760  { "topleft", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP_LEFT}, 0, 0, FLAGS, "chroma" },
761  { "top", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_TOP}, 0, 0, FLAGS, "chroma" },
762  { "bottomleft",0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM_LEFT}, 0, 0, FLAGS, "chroma" },
763  { "bottom", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_CHROMA_BOTTOM}, 0, 0, FLAGS, "chroma" },
764  { "chromalin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
765  { "cin", "set input chroma location", OFFSET(chromal_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_CHROMA_BOTTOM, FLAGS, "chroma" },
766  { "npl", "set nominal peak luminance", OFFSET(nominal_peak_luminance), AV_OPT_TYPE_DOUBLE, {.dbl = NAN}, 0, DBL_MAX, FLAGS },
767  { "agamma", "allow approximate gamma", OFFSET(approximate_gamma), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
768  { NULL }
769 };
770 
771 static const AVClass zscale_class = {
772  .class_name = "zscale",
773  .item_name = av_default_item_name,
774  .option = zscale_options,
775  .version = LIBAVUTIL_VERSION_INT,
776  .category = AV_CLASS_CATEGORY_FILTER,
777 };
778 
780  {
781  .name = "default",
782  .type = AVMEDIA_TYPE_VIDEO,
783  .filter_frame = filter_frame,
784  },
785  { NULL }
786 };
787 
789  {
790  .name = "default",
791  .type = AVMEDIA_TYPE_VIDEO,
792  .config_props = config_props,
793  },
794  { NULL }
795 };
796 
798  .name = "zscale",
799  .description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
800  .init_dict = init_dict,
801  .query_formats = query_formats,
802  .priv_size = sizeof(ZScaleContext),
803  .priv_class = &zscale_class,
804  .uninit = uninit,
805  .inputs = avfilter_vf_zscale_inputs,
806  .outputs = avfilter_vf_zscale_outputs,
808 };
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:439
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:453
int plane
Definition: avisynth_c.h:422
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition: vf_zscale.c:788
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:388
const char * s
Definition: avisynth_c.h:768
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:382
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:497
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
int out_v_chr_pos
Definition: vf_zscale.c:106
AVOption.
Definition: opt.h:246
"Linear transfer characteristics"
Definition: pixfmt.h:432
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:384
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:148
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:361
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:385
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:60
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:457
SMPTE ST 432-1 (2010) / P3 D65 / Display P3.
Definition: pixfmt.h:415
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int num
Numerator.
Definition: rational.h:59
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:367
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:458
zimg_image_format dst_format
Definition: vf_zscale.c:115
color_range
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:355
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
int approximate_gamma
Definition: vf_zscale.c:100
zimg_graph_builder_params alpha_params
Definition: vf_zscale.c:117
enum AVColorSpace in_colorspace out_colorspace
Definition: vf_zscale.c:120
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:452
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:423
char * w_expr
width expression string
Definition: vf_zscale.c:102
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
zimg_filter_graph * alpha_graph
Definition: vf_zscale.c:118
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:331
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1125
static int print_zimg_error(AVFilterContext *ctx)
Definition: vf_zscale.c:315
enum AVColorPrimaries in_primaries out_primaries
Definition: vf_zscale.c:122
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
zimg_image_format alpha_dst_format
Definition: vf_zscale.c:116
#define av_cold
Definition: attributes.h:82
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:173
#define av_malloc(s)
AVOptions.
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:451
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: pixfmt.h:460
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
Definition: cfhd.c:80
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:381
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:366
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
static int flags
Definition: log.c:57
int in_h_chr_pos
Definition: vf_zscale.c:107
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static const AVFilterPad avfilter_vf_zscale_inputs[]
Definition: vf_zscale.c:779
static int convert_range(enum AVColorRange color_range)
Definition: vf_zscale.c:412
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:364
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:473
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
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:356
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:387
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:400
#define av_log(a,...)
static int convert_matrix(enum AVColorSpace colorspace)
Definition: vf_zscale.c:345
static int query_formats(AVFilterContext *ctx)
Definition: vf_zscale.c:161
A filter pad used for either input or output.
Definition: internal.h:54
enum AVColorRange in_range out_range
Definition: vf_zscale.c:123
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:726
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
int width
width and height of the video frame
Definition: frame.h:239
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: vf_zscale.c:127
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
static int filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_zscale.c:424
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void * tmp
Definition: vf_zscale.c:112
static const uint8_t dither[8][8]
Definition: vf_fspp.c:57
void * priv
private data for use by the filter
Definition: avfilter.h:338
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:423
#define OFFSET(x)
Definition: vf_zscale.c:687
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:389
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:434
zimg_image_format alpha_src_format
Definition: vf_zscale.c:116
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:402
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:354
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:89
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:373
int w
New dimensions.
Definition: vf_zscale.c:85
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
var_name
Definition: aeval.c:46
common internal API header
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:349
AVDictionary * opts
Definition: movenc.c:50
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:440
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:370
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:129
#define FFMIN(a, b)
Definition: common.h:96
char * size_str
Definition: vf_zscale.c:98
zimg_filter_graph * graph
Definition: vf_zscale.c:118
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
static void uninit(AVFilterContext *ctx)
Definition: vf_zscale.c:654
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:462
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:499
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:386
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:350
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:369
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:476
int colorspace_in
Definition: vf_zscale.c:93
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:362
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:251
also ITU-R BT1361
Definition: pixfmt.h:425
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:430
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:359
zimg_graph_builder_params params
Definition: vf_zscale.c:117
double nominal_peak_luminance
Definition: vf_zscale.c:99
int chromal_in
Definition: vf_zscale.c:97
functionally identical to above
Definition: pixfmt.h:409
enum AVChromaLocation in_chromal out_chromal
Definition: vf_zscale.c:124
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static int convert_trc(enum AVColorTransferCharacteristic color_trc)
Definition: vf_zscale.c:368
static const char *const var_names[]
Definition: vf_zscale.c:46
char * h_expr
height expression string
Definition: vf_zscale.c:103
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:266
zimg_image_format src_format
Definition: vf_zscale.c:115
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int out_h_chr_pos
Definition: vf_zscale.c:105
void * buf
Definition: avisynth_c.h:690
int primaries_in
Definition: vf_zscale.c:95
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:351
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_zscale.c:663
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
int colorspace
Definition: vf_zscale.c:88
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition: vf_zscale.c:393
Rational number (pair of numerator and denominator).
Definition: rational.h:58
const char * name
Filter name.
Definition: avfilter.h:148
static int convert_chroma_location(enum AVChromaLocation chroma_location)
Definition: vf_zscale.c:325
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:348
enum AVChromaLocation chroma_location
Definition: frame.h:436
#define snprintf
Definition: snprintf.h:34
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:335
static const AVClass zscale_class
Definition: vf_zscale.c:771
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:360
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:368
size_t tmp_size
Definition: vf_zscale.c:113
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:352
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:358
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:475
static int config_props(AVFilterLink *outlink)
Definition: vf_zscale.c:192
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:463
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:437
if(ret< 0)
Definition: vf_mcdeint.c:282
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
AVFilter ff_vf_zscale
Definition: vf_zscale.c:797
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:383
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
static const AVOption zscale_options[]
Definition: vf_zscale.c:690
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int den
Denominator.
Definition: rational.h:60
int force_original_aspect_ratio
Definition: vf_zscale.c:110
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:444
#define NAN
Definition: math.h:28
#define FLAGS
Definition: vf_zscale.c:688
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
int in_v_chr_pos
Definition: vf_zscale.c:108
enum AVColorPrimaries color_primaries
Definition: frame.h:425
An instance of a filter.
Definition: avfilter.h:323
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:438
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:408
ITU-R BT2020.
Definition: pixfmt.h:411
int height
Definition: frame.h:239
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:495
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:427
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:498
#define FFSWAP(type, a, b)
Definition: common.h:99
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:2249
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:449
enum AVColorTransferCharacteristic in_trc out_trc
Definition: vf_zscale.c:121
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:363
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:596
simple arithmetic expression evaluator