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 <stdio.h>
27 #include <string.h>
28 
29 #include <zimg.h>
30 
31 #include "avfilter.h"
32 #include "formats.h"
33 #include "internal.h"
34 #include "video.h"
35 #include "libavutil/avstring.h"
36 #include "libavutil/eval.h"
37 #include "libavutil/internal.h"
38 #include "libavutil/mathematics.h"
39 #include "libavutil/opt.h"
40 #include "libavutil/parseutils.h"
41 #include "libavutil/pixdesc.h"
42 #include "libavutil/imgutils.h"
43 #include "libavutil/avassert.h"
44 
45 static const char *const var_names[] = {
46  "in_w", "iw",
47  "in_h", "ih",
48  "out_w", "ow",
49  "out_h", "oh",
50  "a",
51  "sar",
52  "dar",
53  "hsub",
54  "vsub",
55  "ohsub",
56  "ovsub",
57  NULL
58 };
59 
60 enum var_name {
73 };
74 
75 typedef struct ZScaleContext {
76  const AVClass *class;
77 
78  /**
79  * New dimensions. Special values are:
80  * 0 = original width/height
81  * -1 = keep original aspect
82  * -N = try to keep aspect but make sure it is divisible by N
83  */
84  int w, h;
85  int dither;
86  int filter;
88  int trc;
89  int primaries;
90  int range;
92  int trc_in;
94  int range_in;
95  char *size_str;
96 
97  char *w_expr; ///< width expression string
98  char *h_expr; ///< height expression string
99 
104 
106 
107  void *tmp;
108  size_t tmp_size;
109 
110  zimg_image_format src_format, dst_format;
111  zimg_image_format alpha_src_format, alpha_dst_format;
112  zimg_graph_builder_params alpha_params, params;
113  zimg_filter_graph *alpha_graph, *graph;
114 
115  enum AVColorSpace in_colorspace, out_colorspace;
117  enum AVColorPrimaries in_primaries, out_primaries;
118  enum AVColorRange in_range, out_range;
119 } ZScaleContext;
120 
122 {
123  ZScaleContext *s = ctx->priv;
124  int ret;
125 
126  if (s->size_str && (s->w_expr || s->h_expr)) {
127  av_log(ctx, AV_LOG_ERROR,
128  "Size and width/height expressions cannot be set at the same time.\n");
129  return AVERROR(EINVAL);
130  }
131 
132  if (s->w_expr && !s->h_expr)
133  FFSWAP(char *, s->w_expr, s->size_str);
134 
135  if (s->size_str) {
136  char buf[32];
137  if ((ret = av_parse_video_size(&s->w, &s->h, s->size_str)) < 0) {
138  av_log(ctx, AV_LOG_ERROR,
139  "Invalid size '%s'\n", s->size_str);
140  return ret;
141  }
142  snprintf(buf, sizeof(buf)-1, "%d", s->w);
143  av_opt_set(s, "w", buf, 0);
144  snprintf(buf, sizeof(buf)-1, "%d", s->h);
145  av_opt_set(s, "h", buf, 0);
146  }
147  if (!s->w_expr)
148  av_opt_set(s, "w", "iw", 0);
149  if (!s->h_expr)
150  av_opt_set(s, "h", "ih", 0);
151 
152  return 0;
153 }
154 
156 {
157  static const enum AVPixelFormat pixel_fmts[] = {
177  };
178  int ret;
179 
180  ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->out_formats);
181  if (ret < 0)
182  return ret;
183  return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->in_formats);
184 }
185 
186 static int config_props(AVFilterLink *outlink)
187 {
188  AVFilterContext *ctx = outlink->src;
189  AVFilterLink *inlink = outlink->src->inputs[0];
190  ZScaleContext *s = ctx->priv;
192  const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(outlink->format);
193  int64_t w, h;
194  double var_values[VARS_NB], res;
195  char *expr;
196  int ret;
197  int factor_w, factor_h;
198 
199  var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
200  var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
201  var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
202  var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
203  var_values[VAR_A] = (double) inlink->w / inlink->h;
204  var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
205  (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
206  var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
207  var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
208  var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
209  var_values[VAR_OHSUB] = 1 << out_desc->log2_chroma_w;
210  var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h;
211 
212  /* evaluate width and height */
213  av_expr_parse_and_eval(&res, (expr = s->w_expr),
214  var_names, var_values,
215  NULL, NULL, NULL, NULL, NULL, 0, ctx);
216  s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
217  if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),
218  var_names, var_values,
219  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
220  goto fail;
221  s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
222  /* evaluate again the width, as it may depend on the output height */
223  if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),
224  var_names, var_values,
225  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
226  goto fail;
227  s->w = res;
228 
229  w = s->w;
230  h = s->h;
231 
232  /* Check if it is requested that the result has to be divisible by a some
233  * factor (w or h = -n with n being the factor). */
234  factor_w = 1;
235  factor_h = 1;
236  if (w < -1) {
237  factor_w = -w;
238  }
239  if (h < -1) {
240  factor_h = -h;
241  }
242 
243  if (w < 0 && h < 0)
244  s->w = s->h = 0;
245 
246  if (!(w = s->w))
247  w = inlink->w;
248  if (!(h = s->h))
249  h = inlink->h;
250 
251  /* Make sure that the result is divisible by the factor we determined
252  * earlier. If no factor was set, it is nothing will happen as the default
253  * factor is 1 */
254  if (w < 0)
255  w = av_rescale(h, inlink->w, inlink->h * factor_w) * factor_w;
256  if (h < 0)
257  h = av_rescale(w, inlink->h, inlink->w * factor_h) * factor_h;
258 
259  /* Note that force_original_aspect_ratio may overwrite the previous set
260  * dimensions so that it is not divisible by the set factors anymore. */
262  int tmp_w = av_rescale(h, inlink->w, inlink->h);
263  int tmp_h = av_rescale(w, inlink->h, inlink->w);
264 
265  if (s->force_original_aspect_ratio == 1) {
266  w = FFMIN(tmp_w, w);
267  h = FFMIN(tmp_h, h);
268  } else {
269  w = FFMAX(tmp_w, w);
270  h = FFMAX(tmp_h, h);
271  }
272  }
273 
274  if (w > INT_MAX || h > INT_MAX ||
275  (h * inlink->w) > INT_MAX ||
276  (w * inlink->h) > INT_MAX)
277  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
278 
279  outlink->w = w;
280  outlink->h = h;
281 
282  if (inlink->w == outlink->w &&
283  inlink->h == outlink->h &&
284  inlink->format == outlink->format)
285  ;
286  else {
287  }
288 
289  if (inlink->sample_aspect_ratio.num){
290  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
291  } else
292  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
293 
294  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",
295  inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
297  outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
298  outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
299  return 0;
300 
301 fail:
302  av_log(ctx, AV_LOG_ERROR,
303  "Error when evaluating the expression '%s'.\n"
304  "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
305  expr, s->w_expr, s->h_expr);
306  return ret;
307 }
308 
310 {
311  char err_msg[1024];
312  int err_code = zimg_get_last_error(err_msg, sizeof(err_msg));
313 
314  av_log(ctx, AV_LOG_ERROR, "code %d: %s\n", err_code, err_msg);
315 
316  return err_code;
317 }
318 
319 static int convert_matrix(enum AVColorSpace colorspace)
320 {
321  switch (colorspace) {
322  case AVCOL_SPC_RGB:
323  return ZIMG_MATRIX_RGB;
324  case AVCOL_SPC_BT709:
325  return ZIMG_MATRIX_709;
327  return ZIMG_MATRIX_UNSPECIFIED;
328  case AVCOL_SPC_BT470BG:
329  return ZIMG_MATRIX_470BG;
330  case AVCOL_SPC_SMPTE170M:
331  return ZIMG_MATRIX_170M;
332  case AVCOL_SPC_YCGCO:
333  return ZIMG_MATRIX_YCGCO;
335  return ZIMG_MATRIX_2020_NCL;
336  case AVCOL_SPC_BT2020_CL:
337  return ZIMG_MATRIX_2020_CL;
338  }
339  return ZIMG_MATRIX_UNSPECIFIED;
340 }
341 
342 static int convert_trc(enum AVColorTransferCharacteristic color_trc)
343 {
344  switch (color_trc) {
346  return ZIMG_TRANSFER_UNSPECIFIED;
347  case AVCOL_TRC_BT709:
348  return ZIMG_TRANSFER_709;
349  case AVCOL_TRC_SMPTE170M:
350  return ZIMG_TRANSFER_601;
351  case AVCOL_TRC_LINEAR:
352  return ZIMG_TRANSFER_LINEAR;
353  case AVCOL_TRC_BT2020_10:
354  return ZIMG_TRANSFER_2020_10;
355  case AVCOL_TRC_BT2020_12:
356  return ZIMG_TRANSFER_2020_12;
357  }
358  return ZIMG_TRANSFER_UNSPECIFIED;
359 }
360 
362 {
363  switch (color_primaries) {
365  return ZIMG_PRIMARIES_UNSPECIFIED;
366  case AVCOL_PRI_BT709:
367  return ZIMG_PRIMARIES_709;
368  case AVCOL_PRI_SMPTE170M:
369  return ZIMG_PRIMARIES_170M;
370  case AVCOL_PRI_SMPTE240M:
371  return ZIMG_PRIMARIES_240M;
372  case AVCOL_PRI_BT2020:
373  return ZIMG_PRIMARIES_2020;
374  }
375  return ZIMG_PRIMARIES_UNSPECIFIED;
376 }
377 
379 {
380  switch (color_range) {
382  case AVCOL_RANGE_MPEG:
383  return ZIMG_RANGE_LIMITED;
384  case AVCOL_RANGE_JPEG:
385  return ZIMG_RANGE_FULL;
386  }
387  return ZIMG_RANGE_LIMITED;
388 }
389 
390 static int filter_frame(AVFilterLink *link, AVFrame *in)
391 {
392  ZScaleContext *s = link->dst->priv;
393  AVFilterLink *outlink = link->dst->outputs[0];
395  const AVPixFmtDescriptor *odesc = av_pix_fmt_desc_get(outlink->format);
396  zimg_image_buffer_const src_buf = { ZIMG_API_VERSION };
397  zimg_image_buffer dst_buf = { ZIMG_API_VERSION };
398  char buf[32];
399  size_t tmp_size;
400  int ret = 0, plane;
401  AVFrame *out;
402 
403  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
404  if (!out) {
405  av_frame_free(&in);
406  return AVERROR(ENOMEM);
407  }
408 
409  av_frame_copy_props(out, in);
410  out->width = outlink->w;
411  out->height = outlink->h;
412 
413  if( in->width != link->w
414  || in->height != link->h
415  || in->format != link->format
416  || s->in_colorspace != in->colorspace
417  || s->in_trc != in->color_trc
418  || s->in_primaries != in->color_primaries
419  || s->in_range != in->color_range
420  || s->out_colorspace != out->colorspace
421  || s->out_trc != out->color_trc
422  || s->out_primaries != out->color_primaries
423  || s->out_range != out->color_range) {
424  snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
425  av_opt_set(s, "w", buf, 0);
426  snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
427  av_opt_set(s, "h", buf, 0);
428 
429  link->dst->inputs[0]->format = in->format;
430  link->dst->inputs[0]->w = in->width;
431  link->dst->inputs[0]->h = in->height;
432 
433  if ((ret = config_props(outlink)) < 0) {
434  av_frame_free(&in);
435  av_frame_free(&out);
436  return ret;
437  }
438 
439  zimg_image_format_default(&s->src_format, ZIMG_API_VERSION);
440  zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION);
441  zimg_graph_builder_params_default(&s->params, ZIMG_API_VERSION);
442 
443  s->params.dither_type = s->dither;
444  s->params.cpu_type = ZIMG_CPU_AUTO;
445  s->params.resample_filter = s->filter;
446  s->params.resample_filter_uv = s->filter;
447 
448  s->src_format.width = in->width;
449  s->src_format.height = in->height;
450  s->src_format.subsample_w = desc->log2_chroma_w;
451  s->src_format.subsample_h = desc->log2_chroma_h;
452  s->src_format.depth = desc->comp[0].depth;
453  s->src_format.pixel_type = desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
454  s->src_format.color_family = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
455  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;
456  s->src_format.transfer_characteristics = s->trc_in == - 1 ? convert_trc(in->color_trc) : s->trc_in;
457  s->src_format.color_primaries = s->primaries_in == -1 ? convert_primaries(in->color_primaries) : s->primaries_in;
458  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;
459 
460  s->dst_format.width = out->width;
461  s->dst_format.height = out->height;
462  s->dst_format.subsample_w = odesc->log2_chroma_w;
463  s->dst_format.subsample_h = odesc->log2_chroma_h;
464  s->dst_format.depth = odesc->comp[0].depth;
465  s->dst_format.pixel_type = odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
466  s->dst_format.color_family = (odesc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_COLOR_RGB : ZIMG_COLOR_YUV;
467  s->dst_format.matrix_coefficients = (odesc->flags & AV_PIX_FMT_FLAG_RGB) ? ZIMG_MATRIX_RGB : s->colorspace == -1 ? convert_matrix(out->colorspace) : s->colorspace;
468  s->dst_format.transfer_characteristics = s->trc == -1 ? convert_trc(out->color_trc) : s->trc;
469  s->dst_format.color_primaries = s->primaries == -1 ? convert_primaries(out->color_primaries) : s->primaries;
470  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;
471 
472  if (s->colorspace != -1)
473  out->colorspace = (int)s->dst_format.matrix_coefficients;
474 
475  if (s->primaries != -1)
476  out->color_primaries = (int)s->dst_format.color_primaries;
477 
478  if (s->range != -1)
479  out->color_range = (int)s->dst_format.pixel_range + 1;
480 
481  if (s->trc != -1)
482  out->color_trc = (int)s->dst_format.transfer_characteristics;
483 
484  zimg_filter_graph_free(s->graph);
485  s->graph = zimg_filter_graph_build(&s->src_format, &s->dst_format, &s->params);
486  if (!s->graph) {
487  ret = print_zimg_error(link->dst);
488  goto fail;
489  }
490 
491  if ((ret = zimg_filter_graph_get_tmp_size(s->graph, &tmp_size))) {
492  ret = print_zimg_error(link->dst);
493  goto fail;
494  }
495 
496  if (tmp_size > s->tmp_size) {
497  av_freep(&s->tmp);
498  s->tmp = av_malloc(tmp_size);
499  if (!s->tmp) {
500  ret = AVERROR(ENOMEM);
501  goto fail;
502  }
503  s->tmp_size = tmp_size;
504  }
505 
506  s->in_colorspace = in->colorspace;
507  s->in_trc = in->color_trc;
508  s->in_primaries = in->color_primaries;
509  s->in_range = in->color_range;
510  s->out_colorspace = out->colorspace;
511  s->out_trc = out->color_trc;
512  s->out_primaries = out->color_primaries;
513  s->out_range = out->color_range;
514 
515  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
516  zimg_image_format_default(&s->alpha_src_format, ZIMG_API_VERSION);
517  zimg_image_format_default(&s->alpha_dst_format, ZIMG_API_VERSION);
518  zimg_graph_builder_params_default(&s->alpha_params, ZIMG_API_VERSION);
519 
520  s->alpha_params.dither_type = s->dither;
521  s->alpha_params.cpu_type = ZIMG_CPU_AUTO;
522  s->alpha_params.resample_filter = s->filter;
523 
524  s->alpha_src_format.width = in->width;
525  s->alpha_src_format.height = in->height;
526  s->alpha_src_format.depth = desc->comp[0].depth;
527  s->alpha_src_format.pixel_type = desc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
528  s->alpha_src_format.color_family = ZIMG_COLOR_GREY;
529 
530  s->alpha_dst_format.width = out->width;
531  s->alpha_dst_format.height = out->height;
532  s->alpha_dst_format.depth = odesc->comp[0].depth;
533  s->alpha_dst_format.pixel_type = odesc->comp[0].depth > 8 ? ZIMG_PIXEL_WORD : ZIMG_PIXEL_BYTE;
534  s->alpha_dst_format.color_family = ZIMG_COLOR_GREY;
535 
536  zimg_filter_graph_free(s->alpha_graph);
537  s->alpha_graph = zimg_filter_graph_build(&s->alpha_src_format, &s->alpha_dst_format, &s->alpha_params);
538  if (!s->alpha_graph) {
539  ret = print_zimg_error(link->dst);
540  goto fail;
541  }
542  }
543  }
544 
545  if (s->colorspace != -1)
546  out->colorspace = (int)s->dst_format.matrix_coefficients;
547 
548  if (s->primaries != -1)
549  out->color_primaries = (int)s->dst_format.color_primaries;
550 
551  if (s->range != -1)
552  out->color_range = (int)s->dst_format.pixel_range;
553 
554  if (s->trc != -1)
555  out->color_trc = (int)s->dst_format.transfer_characteristics;
556 
558  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
559  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
560  INT_MAX);
561 
562  for (plane = 0; plane < 3; plane++) {
563  int p = desc->comp[plane].plane;
564  src_buf.plane[plane].data = in->data[p];
565  src_buf.plane[plane].stride = in->linesize[p];
566  src_buf.plane[plane].mask = -1;
567 
568  p = odesc->comp[plane].plane;
569  dst_buf.plane[plane].data = out->data[p];
570  dst_buf.plane[plane].stride = out->linesize[p];
571  dst_buf.plane[plane].mask = -1;
572  }
573 
574  ret = zimg_filter_graph_process(s->graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
575  if (ret) {
576  print_zimg_error(link->dst);
577  goto fail;
578  }
579 
580  if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
581  src_buf.plane[0].data = in->data[3];
582  src_buf.plane[0].stride = in->linesize[3];
583  src_buf.plane[0].mask = -1;
584 
585  dst_buf.plane[0].data = out->data[3];
586  dst_buf.plane[0].stride = out->linesize[3];
587  dst_buf.plane[0].mask = -1;
588 
589  ret = zimg_filter_graph_process(s->alpha_graph, &src_buf, &dst_buf, s->tmp, 0, 0, 0, 0);
590  if (ret) {
591  print_zimg_error(link->dst);
592  goto fail;
593  }
594  } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) {
595  int y;
596 
597  for (y = 0; y < outlink->h; y++)
598  memset(out->data[3] + y * out->linesize[3], 0xff, outlink->w);
599  }
600 
601 fail:
602  av_frame_free(&in);
603  if (ret) {
604  av_frame_free(&out);
605  return ret;
606  }
607 
608  return ff_filter_frame(outlink, out);
609 }
610 
612 {
613  ZScaleContext *s = ctx->priv;
614 
615  zimg_filter_graph_free(s->graph);
616  av_freep(&s->tmp);
617  s->tmp_size = 0;
618 }
619 
620 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
621  char *res, int res_len, int flags)
622 {
623  ZScaleContext *s = ctx->priv;
624  int ret;
625 
626  if ( !strcmp(cmd, "width") || !strcmp(cmd, "w")
627  || !strcmp(cmd, "height") || !strcmp(cmd, "h")) {
628 
629  int old_w = s->w;
630  int old_h = s->h;
631  AVFilterLink *outlink = ctx->outputs[0];
632 
633  av_opt_set(s, cmd, args, 0);
634  if ((ret = config_props(outlink)) < 0) {
635  s->w = old_w;
636  s->h = old_h;
637  }
638  } else
639  ret = AVERROR(ENOSYS);
640 
641  return ret;
642 }
643 
644 #define OFFSET(x) offsetof(ZScaleContext, x)
645 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
646 
647 static const AVOption zscale_options[] = {
648  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
649  { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
650  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
651  { "height", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
652  { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
653  { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
654  { "dither", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
655  { "d", "set dither type", OFFSET(dither), AV_OPT_TYPE_INT, {.i64 = 0}, 0, ZIMG_DITHER_ERROR_DIFFUSION, FLAGS, "dither" },
656  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_NONE}, 0, 0, FLAGS, "dither" },
657  { "ordered", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ORDERED}, 0, 0, FLAGS, "dither" },
658  { "random", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_RANDOM}, 0, 0, FLAGS, "dither" },
659  { "error_diffusion", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_DITHER_ERROR_DIFFUSION}, 0, 0, FLAGS, "dither" },
660  { "filter", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
661  { "f", "set filter type", OFFSET(filter), AV_OPT_TYPE_INT, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, ZIMG_RESIZE_LANCZOS, FLAGS, "filter" },
662  { "point", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_POINT}, 0, 0, FLAGS, "filter" },
663  { "bilinear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BILINEAR}, 0, 0, FLAGS, "filter" },
664  { "bicubic", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_BICUBIC}, 0, 0, FLAGS, "filter" },
665  { "spline16", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE16}, 0, 0, FLAGS, "filter" },
666  { "spline36", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_SPLINE36}, 0, 0, FLAGS, "filter" },
667  { "lanczos", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RESIZE_LANCZOS}, 0, 0, FLAGS, "filter" },
668  { "range", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
669  { "r", "set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
670  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "range" },
671  { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_LIMITED}, 0, 0, FLAGS, "range" },
672  { "full", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_RANGE_FULL}, 0, 0, FLAGS, "range" },
673  { "primaries", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020, FLAGS, "primaries" },
674  { "p", "set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020, FLAGS, "primaries" },
675  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "primaries" },
676  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_709}, 0, 0, FLAGS, "primaries" },
677  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_UNSPECIFIED}, 0, 0, FLAGS, "primaries" },
678  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_170M}, 0, 0, FLAGS, "primaries" },
679  { "240m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_240M}, 0, 0, FLAGS, "primaries" },
680  { "2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_PRIMARIES_2020}, 0, 0, FLAGS, "primaries" },
681  { "transfer", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12, FLAGS, "transfer" },
682  { "t", "set transfer characteristic", OFFSET(trc), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12, FLAGS, "transfer" },
683  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "transfer" },
684  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_709}, 0, 0, FLAGS, "transfer" },
685  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_UNSPECIFIED}, 0, 0, FLAGS, "transfer" },
686  { "601", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_601}, 0, 0, FLAGS, "transfer" },
687  { "linear", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_LINEAR}, 0, 0, FLAGS, "transfer" },
688  { "2020_10", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_10}, 0, 0, FLAGS, "transfer" },
689  { "2020_12", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_TRANSFER_2020_12}, 0, 0, FLAGS, "transfer" },
690  { "matrix", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
691  { "m", "set colorspace matrix", OFFSET(colorspace), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
692  { "input", 0, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, "matrix" },
693  { "709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_709}, 0, 0, FLAGS, "matrix" },
694  { "unspecified", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_UNSPECIFIED}, 0, 0, FLAGS, "matrix" },
695  { "470bg", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_470BG}, 0, 0, FLAGS, "matrix" },
696  { "170m", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_170M}, 0, 0, FLAGS, "matrix" },
697  { "ycgco", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_YCGCO}, 0, 0, FLAGS, "matrix" },
698  { "2020_ncl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_NCL}, 0, 0, FLAGS, "matrix" },
699  { "2020_cl", 0, 0, AV_OPT_TYPE_CONST, {.i64 = ZIMG_MATRIX_2020_CL}, 0, 0, FLAGS, "matrix" },
700  { "rangein", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
701  { "rin", "set input color range", OFFSET(range_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_RANGE_FULL, FLAGS, "range" },
702  { "primariesin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020, FLAGS, "primaries" },
703  { "pin", "set input color primaries", OFFSET(primaries_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_PRIMARIES_2020, FLAGS, "primaries" },
704  { "transferin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12, FLAGS, "transfer" },
705  { "tin", "set input transfer characteristic", OFFSET(trc_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_TRANSFER_2020_12, FLAGS, "transfer" },
706  { "matrixin", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
707  { "min", "set input colorspace matrix", OFFSET(colorspace_in), AV_OPT_TYPE_INT, {.i64 = -1}, -1, ZIMG_MATRIX_2020_CL, FLAGS, "matrix" },
708  { NULL }
709 };
710 
711 static const AVClass zscale_class = {
712  .class_name = "zscale",
713  .item_name = av_default_item_name,
714  .option = zscale_options,
715  .version = LIBAVUTIL_VERSION_INT,
716  .category = AV_CLASS_CATEGORY_FILTER,
717 };
718 
720  {
721  .name = "default",
722  .type = AVMEDIA_TYPE_VIDEO,
723  .filter_frame = filter_frame,
724  },
725  { NULL }
726 };
727 
729  {
730  .name = "default",
731  .type = AVMEDIA_TYPE_VIDEO,
732  .config_props = config_props,
733  },
734  { NULL }
735 };
736 
738  .name = "zscale",
739  .description = NULL_IF_CONFIG_SMALL("Apply resizing, colorspace and bit depth conversion."),
740  .init_dict = init_dict,
741  .query_formats = query_formats,
742  .priv_size = sizeof(ZScaleContext),
743  .priv_class = &zscale_class,
744  .uninit = uninit,
745  .inputs = avfilter_vf_zscale_inputs,
746  .outputs = avfilter_vf_zscale_outputs,
748 };
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:424
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:436
int plane
Definition: avisynth_c.h:291
static const AVFilterPad avfilter_vf_zscale_outputs[]
Definition: vf_zscale.c:728
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:378
const char * s
Definition: avisynth_c.h:631
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:372
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2222
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
int out_v_chr_pos
Definition: vf_zscale.c:101
AVOption.
Definition: opt.h:245
"Linear transfer characteristics"
Definition: pixfmt.h:417
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:374
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:143
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:351
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:375
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:70
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:89
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:440
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int num
numerator
Definition: rational.h:44
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:357
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:441
zimg_image_format dst_format
Definition: vf_zscale.c:110
color_range
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:345
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
zimg_graph_builder_params alpha_params
Definition: vf_zscale.c:112
enum AVColorSpace in_colorspace out_colorspace
Definition: vf_zscale.c:115
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:435
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:408
char * w_expr
width expression string
Definition: vf_zscale.c:97
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:59
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:113
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:313
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1180
static int print_zimg_error(AVFilterContext *ctx)
Definition: vf_zscale.c:309
enum AVColorPrimaries in_primaries out_primaries
Definition: vf_zscale.c:117
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:111
#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:434
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:371
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:356
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
int in_h_chr_pos
Definition: vf_zscale.c:102
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:719
static int convert_range(enum AVColorRange color_range)
Definition: vf_zscale.c:378
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:354
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:454
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:346
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:377
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:389
#define av_log(a,...)
static int convert_matrix(enum AVColorSpace colorspace)
Definition: vf_zscale.c:319
static int query_formats(AVFilterContext *ctx)
Definition: vf_zscale.c:155
A filter pad used for either input or output.
Definition: internal.h:53
enum AVColorRange in_range out_range
Definition: vf_zscale.c:118
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:723
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:187
int width
width and height of the video frame
Definition: frame.h:236
#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:121
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:390
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:153
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void * tmp
Definition: vf_zscale.c:107
static const uint8_t dither[8][8]
Definition: vf_fspp.c:57
void * priv
private data for use by the filter
Definition: avfilter.h:320
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:413
#define OFFSET(x)
Definition: vf_zscale.c:644
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:379
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:426
zimg_image_format alpha_src_format
Definition: vf_zscale.c:111
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
Definition: pixfmt.h:391
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:344
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:81
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:363
int w
New dimensions.
Definition: vf_zscale.c:84
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
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
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:339
AVDictionary * opts
Definition: movenc.c:50
#define AVCOL_SPC_YCGCO
Definition: pixfmt.h:448
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:360
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:95
zimg_filter_graph * graph
Definition: vf_zscale.c:113
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:611
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:444
static const struct ColorPrimaries color_primaries[AVCOL_PRI_NB]
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:376
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:340
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:359
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:457
int colorspace_in
Definition: vf_zscale.c:91
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:352
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
also ITU-R BT1361
Definition: pixfmt.h:410
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:415
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:349
zimg_graph_builder_params params
Definition: vf_zscale.c:112
functionally identical to above
Definition: pixfmt.h:398
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:188
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:342
static const char *const var_names[]
Definition: vf_zscale.c:45
char * h_expr
height expression string
Definition: vf_zscale.c:98
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:263
zimg_image_format src_format
Definition: vf_zscale.c:110
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:100
void * buf
Definition: avisynth_c.h:553
int primaries_in
Definition: vf_zscale.c:93
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:341
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_zscale.c:620
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
int colorspace
Definition: vf_zscale.c:87
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:142
static int convert_primaries(enum AVColorPrimaries color_primaries)
Definition: vf_zscale.c:361
rational number numerator/denominator
Definition: rational.h:43
const char * name
Filter name.
Definition: avfilter.h:146
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:338
#define snprintf
Definition: snprintf.h:34
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:317
static const AVClass zscale_class
Definition: vf_zscale.c:711
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:350
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:358
size_t tmp_size
Definition: vf_zscale.c:108
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:342
static int flags
Definition: cpu.c:47
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:348
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:456
static int config_props(AVFilterLink *outlink)
Definition: vf_zscale.c:186
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:445
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
if(ret< 0)
Definition: vf_mcdeint.c:282
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:228
AVFilter ff_vf_zscale
Definition: vf_zscale.c:737
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:373
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:647
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
int den
denominator
Definition: rational.h:45
int force_original_aspect_ratio
Definition: vf_zscale.c:105
#define NAN
Definition: math.h:28
#define FLAGS
Definition: vf_zscale.c:645
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:271
int in_v_chr_pos
Definition: vf_zscale.c:103
enum AVColorPrimaries color_primaries
Definition: frame.h:415
An instance of a filter.
Definition: avfilter.h:305
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:423
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:397
ITU-R BT2020.
Definition: pixfmt.h:400
int height
Definition: frame.h:236
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
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:417
#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:2138
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:431
enum AVColorTransferCharacteristic in_trc out_trc
Definition: vf_zscale.c:116
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:353
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:580
simple arithmetic expression evaluator