FFmpeg
vf_scale_npp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * scale video filter
22  */
23 
24 #include <nppi.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include "libavutil/avstring.h"
29 #include "libavutil/common.h"
30 #include "libavutil/hwcontext.h"
32 #include "libavutil/cuda_check.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 
37 #include "avfilter.h"
38 #include "formats.h"
39 #include "internal.h"
40 #include "scale_eval.h"
41 #include "video.h"
42 
43 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
44 
45 static const enum AVPixelFormat supported_formats[] = {
49 };
50 
51 static const enum AVPixelFormat deinterleaved_formats[][2] = {
53 };
54 
55 enum ScaleStage {
60 };
61 
62 typedef struct NPPScaleStageContext {
66 
67  struct {
68  int width;
69  int height;
70  } planes_in[3], planes_out[3];
71 
75 
76 typedef struct NPPScaleContext {
77  const AVClass *class;
78 
82 
84 
85  /**
86  * New dimensions. Special values are:
87  * 0 = original width/height
88  * -1 = keep original aspect
89  */
90  int w, h;
91 
92  /**
93  * Output sw format. AV_PIX_FMT_NONE for no conversion.
94  */
96 
97  char *w_expr; ///< width expression string
98  char *h_expr; ///< height expression string
99  char *format_str;
100 
103 
106 
108 {
109  NPPScaleContext *s = ctx->priv;
110  int i;
111 
112  if (!strcmp(s->format_str, "same")) {
113  s->format = AV_PIX_FMT_NONE;
114  } else {
115  s->format = av_get_pix_fmt(s->format_str);
116  if (s->format == AV_PIX_FMT_NONE) {
117  av_log(ctx, AV_LOG_ERROR, "Unrecognized pixel format: %s\n", s->format_str);
118  return AVERROR(EINVAL);
119  }
120  }
121 
122  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
123  s->stages[i].frame = av_frame_alloc();
124  if (!s->stages[i].frame)
125  return AVERROR(ENOMEM);
126  }
127  s->tmp_frame = av_frame_alloc();
128  if (!s->tmp_frame)
129  return AVERROR(ENOMEM);
130 
131  return 0;
132 }
133 
135 {
136  NPPScaleContext *s = ctx->priv;
137  int i;
138 
139  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
140  av_frame_free(&s->stages[i].frame);
141  av_buffer_unref(&s->stages[i].frames_ctx);
142  }
143  av_frame_free(&s->tmp_frame);
144 }
145 
147 {
148  static const enum AVPixelFormat pixel_formats[] = {
150  };
151  return ff_set_common_formats_from_list(ctx, pixel_formats);
152 }
153 
154 static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
155 {
156  AVBufferRef *out_ref = NULL;
157  AVHWFramesContext *out_ctx;
158  int in_sw, in_sh, out_sw, out_sh;
159  int ret, i;
160 
161  av_pix_fmt_get_chroma_sub_sample(stage->in_fmt, &in_sw, &in_sh);
162  av_pix_fmt_get_chroma_sub_sample(stage->out_fmt, &out_sw, &out_sh);
163  if (!stage->planes_out[0].width) {
164  stage->planes_out[0].width = stage->planes_in[0].width;
165  stage->planes_out[0].height = stage->planes_in[0].height;
166  }
167 
168  for (i = 1; i < FF_ARRAY_ELEMS(stage->planes_in); i++) {
169  stage->planes_in[i].width = stage->planes_in[0].width >> in_sw;
170  stage->planes_in[i].height = stage->planes_in[0].height >> in_sh;
171  stage->planes_out[i].width = stage->planes_out[0].width >> out_sw;
172  stage->planes_out[i].height = stage->planes_out[0].height >> out_sh;
173  }
174 
175  out_ref = av_hwframe_ctx_alloc(device_ctx);
176  if (!out_ref)
177  return AVERROR(ENOMEM);
178  out_ctx = (AVHWFramesContext*)out_ref->data;
179 
180  out_ctx->format = AV_PIX_FMT_CUDA;
181  out_ctx->sw_format = stage->out_fmt;
182  out_ctx->width = FFALIGN(stage->planes_out[0].width, 32);
183  out_ctx->height = FFALIGN(stage->planes_out[0].height, 32);
184 
185  ret = av_hwframe_ctx_init(out_ref);
186  if (ret < 0)
187  goto fail;
188 
189  av_frame_unref(stage->frame);
190  ret = av_hwframe_get_buffer(out_ref, stage->frame, 0);
191  if (ret < 0)
192  goto fail;
193 
194  stage->frame->width = stage->planes_out[0].width;
195  stage->frame->height = stage->planes_out[0].height;
196 
197  av_buffer_unref(&stage->frames_ctx);
198  stage->frames_ctx = out_ref;
199 
200  return 0;
201 fail:
202  av_buffer_unref(&out_ref);
203  return ret;
204 }
205 
206 static int format_is_supported(enum AVPixelFormat fmt)
207 {
208  int i;
209 
210  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
211  if (supported_formats[i] == fmt)
212  return 1;
213  return 0;
214 }
215 
217 {
219  int i, planes;
220 
222  if (planes == desc->nb_components)
223  return fmt;
224  for (i = 0; i < FF_ARRAY_ELEMS(deinterleaved_formats); i++)
225  if (deinterleaved_formats[i][0] == fmt)
226  return deinterleaved_formats[i][1];
227  return AV_PIX_FMT_NONE;
228 }
229 
230 static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
231  int out_width, int out_height)
232 {
233  NPPScaleContext *s = ctx->priv;
234 
235  AVHWFramesContext *in_frames_ctx;
236 
237  enum AVPixelFormat in_format;
238  enum AVPixelFormat out_format;
239  enum AVPixelFormat in_deinterleaved_format;
240  enum AVPixelFormat out_deinterleaved_format;
241 
242  int i, ret, last_stage = -1;
243 
244  /* check that we have a hw context */
245  if (!ctx->inputs[0]->hw_frames_ctx) {
246  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
247  return AVERROR(EINVAL);
248  }
249  in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
250  in_format = in_frames_ctx->sw_format;
251  out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
252 
253  if (!format_is_supported(in_format)) {
254  av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
255  av_get_pix_fmt_name(in_format));
256  return AVERROR(ENOSYS);
257  }
258  if (!format_is_supported(out_format)) {
259  av_log(ctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
260  av_get_pix_fmt_name(out_format));
261  return AVERROR(ENOSYS);
262  }
263 
264  in_deinterleaved_format = get_deinterleaved_format(in_format);
265  out_deinterleaved_format = get_deinterleaved_format(out_format);
266  if (in_deinterleaved_format == AV_PIX_FMT_NONE ||
267  out_deinterleaved_format == AV_PIX_FMT_NONE)
268  return AVERROR_BUG;
269 
270  /* figure out which stages need to be done */
271  if (in_width != out_width || in_height != out_height ||
272  in_deinterleaved_format != out_deinterleaved_format) {
273  s->stages[STAGE_RESIZE].stage_needed = 1;
274 
275  if (s->interp_algo == NPPI_INTER_SUPER &&
276  (out_width > in_width && out_height > in_height)) {
277  s->interp_algo = NPPI_INTER_LANCZOS;
278  av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using lanczos instead.\n");
279  }
280  if (s->interp_algo == NPPI_INTER_SUPER &&
281  !(out_width < in_width && out_height < in_height)) {
282  s->interp_algo = NPPI_INTER_CUBIC;
283  av_log(ctx, AV_LOG_WARNING, "super-sampling not supported for output dimensions, using cubic instead.\n");
284  }
285  }
286 
287  if (!s->stages[STAGE_RESIZE].stage_needed && in_format == out_format)
288  s->passthrough = 1;
289 
290  if (!s->passthrough) {
291  if (in_format != in_deinterleaved_format)
292  s->stages[STAGE_DEINTERLEAVE].stage_needed = 1;
293  if (out_format != out_deinterleaved_format)
294  s->stages[STAGE_INTERLEAVE].stage_needed = 1;
295  }
296 
297  s->stages[STAGE_DEINTERLEAVE].in_fmt = in_format;
298  s->stages[STAGE_DEINTERLEAVE].out_fmt = in_deinterleaved_format;
299  s->stages[STAGE_DEINTERLEAVE].planes_in[0].width = in_width;
300  s->stages[STAGE_DEINTERLEAVE].planes_in[0].height = in_height;
301 
302  s->stages[STAGE_RESIZE].in_fmt = in_deinterleaved_format;
303  s->stages[STAGE_RESIZE].out_fmt = out_deinterleaved_format;
304  s->stages[STAGE_RESIZE].planes_in[0].width = in_width;
305  s->stages[STAGE_RESIZE].planes_in[0].height = in_height;
306  s->stages[STAGE_RESIZE].planes_out[0].width = out_width;
307  s->stages[STAGE_RESIZE].planes_out[0].height = out_height;
308 
309  s->stages[STAGE_INTERLEAVE].in_fmt = out_deinterleaved_format;
310  s->stages[STAGE_INTERLEAVE].out_fmt = out_format;
311  s->stages[STAGE_INTERLEAVE].planes_in[0].width = out_width;
312  s->stages[STAGE_INTERLEAVE].planes_in[0].height = out_height;
313 
314  /* init the hardware contexts */
315  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
316  if (!s->stages[i].stage_needed)
317  continue;
318 
319  ret = init_stage(&s->stages[i], in_frames_ctx->device_ref);
320  if (ret < 0)
321  return ret;
322 
323  last_stage = i;
324  }
325 
326  if (last_stage >= 0)
327  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
328  else
329  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
330 
331  if (!ctx->outputs[0]->hw_frames_ctx)
332  return AVERROR(ENOMEM);
333 
334  return 0;
335 }
336 
338 {
339  AVFilterContext *ctx = outlink->src;
340  AVFilterLink *inlink = outlink->src->inputs[0];
341  NPPScaleContext *s = ctx->priv;
342  int w, h;
343  int ret;
344 
346  s->w_expr, s->h_expr,
347  inlink, outlink,
348  &w, &h)) < 0)
349  goto fail;
350 
352  s->force_original_aspect_ratio, s->force_divisible_by);
353 
354  if (((int64_t)h * inlink->w) > INT_MAX ||
355  ((int64_t)w * inlink->h) > INT_MAX)
356  av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
357 
358  outlink->w = w;
359  outlink->h = h;
360 
362  if (ret < 0)
363  return ret;
364 
365  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
366  inlink->w, inlink->h, outlink->w, outlink->h);
367 
368  if (inlink->sample_aspect_ratio.num)
369  outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h*inlink->w,
370  outlink->w*inlink->h},
371  inlink->sample_aspect_ratio);
372  else
373  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
374 
375  return 0;
376 
377 fail:
378  return ret;
379 }
380 
382  AVFrame *out, AVFrame *in)
383 {
384  AVHWFramesContext *in_frames_ctx = (AVHWFramesContext*)in->hw_frames_ctx->data;
385  NppStatus err;
386 
387  switch (in_frames_ctx->sw_format) {
388  case AV_PIX_FMT_NV12:
389  err = nppiYCbCr420_8u_P2P3R(in->data[0], in->linesize[0],
390  in->data[1], in->linesize[1],
391  out->data, out->linesize,
392  (NppiSize){ in->width, in->height });
393  break;
394  default:
395  return AVERROR_BUG;
396  }
397  if (err != NPP_SUCCESS) {
398  av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
399  return AVERROR_UNKNOWN;
400  }
401 
402  return 0;
403 }
404 
406  AVFrame *out, AVFrame *in)
407 {
408  NPPScaleContext *s = ctx->priv;
409  NppStatus err;
410  int i;
411 
412  for (i = 0; i < FF_ARRAY_ELEMS(stage->planes_in) && i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
413  int iw = stage->planes_in[i].width;
414  int ih = stage->planes_in[i].height;
415  int ow = stage->planes_out[i].width;
416  int oh = stage->planes_out[i].height;
417 
418  err = nppiResizeSqrPixel_8u_C1R(in->data[i], (NppiSize){ iw, ih },
419  in->linesize[i], (NppiRect){ 0, 0, iw, ih },
420  out->data[i], out->linesize[i],
421  (NppiRect){ 0, 0, ow, oh },
422  (double)ow / iw, (double)oh / ih,
423  0.0, 0.0, s->interp_algo);
424  if (err != NPP_SUCCESS) {
425  av_log(ctx, AV_LOG_ERROR, "NPP resize error: %d\n", err);
426  return AVERROR_UNKNOWN;
427  }
428  }
429 
430  return 0;
431 }
432 
434  AVFrame *out, AVFrame *in)
435 {
436  AVHWFramesContext *out_frames_ctx = (AVHWFramesContext*)out->hw_frames_ctx->data;
437  NppStatus err;
438 
439  switch (out_frames_ctx->sw_format) {
440  case AV_PIX_FMT_NV12:
441  err = nppiYCbCr420_8u_P3P2R((const uint8_t**)in->data,
442  in->linesize,
443  out->data[0], out->linesize[0],
444  out->data[1], out->linesize[1],
445  (NppiSize){ in->width, in->height });
446  break;
447  default:
448  return AVERROR_BUG;
449  }
450  if (err != NPP_SUCCESS) {
451  av_log(ctx, AV_LOG_ERROR, "NPP deinterleave error: %d\n", err);
452  return AVERROR_UNKNOWN;
453  }
454 
455  return 0;
456 }
457 
459  AVFrame *out, AVFrame *in) = {
463 };
464 
466 {
467  NPPScaleContext *s = ctx->priv;
468  AVFrame *src = in;
469  int i, ret, last_stage = -1;
470 
471  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
472  if (!s->stages[i].stage_needed)
473  continue;
474 
475  ret = nppscale_process[i](ctx, &s->stages[i], s->stages[i].frame, src);
476  if (ret < 0)
477  return ret;
478 
479  src = s->stages[i].frame;
480  last_stage = i;
481  }
482 
483  if (last_stage < 0)
484  return AVERROR_BUG;
485  ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
486  if (ret < 0)
487  return ret;
488 
490  av_frame_move_ref(src, s->tmp_frame);
491 
492  ret = av_frame_copy_props(out, in);
493  if (ret < 0)
494  return ret;
495 
496  return 0;
497 }
498 
500 {
501  AVFilterContext *ctx = link->dst;
502  NPPScaleContext *s = ctx->priv;
503  AVFilterLink *outlink = ctx->outputs[0];
504  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
505  AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
506 
507  AVFrame *out = NULL;
508  CUcontext dummy;
509  int ret = 0;
510 
511  if (s->passthrough)
512  return ff_filter_frame(outlink, in);
513 
514  out = av_frame_alloc();
515  if (!out) {
516  ret = AVERROR(ENOMEM);
517  goto fail;
518  }
519 
520  ret = CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
521  if (ret < 0)
522  goto fail;
523 
524  ret = nppscale_scale(ctx, out, in);
525 
526  CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy));
527  if (ret < 0)
528  goto fail;
529 
530  av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
531  (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
532  (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
533  INT_MAX);
534 
535  av_frame_free(&in);
536  return ff_filter_frame(outlink, out);
537 fail:
538  av_frame_free(&in);
539  av_frame_free(&out);
540  return ret;
541 }
542 
543 #define OFFSET(x) offsetof(NPPScaleContext, x)
544 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
545 static const AVOption options[] = {
546  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS },
547  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS },
548  { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
549 
550  { "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX, FLAGS, "interp_algo" },
551  { "nn", "nearest neighbour", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0, FLAGS, "interp_algo" },
552  { "linear", "linear", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LINEAR }, 0, 0, FLAGS, "interp_algo" },
553  { "cubic", "cubic", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC }, 0, 0, FLAGS, "interp_algo" },
554  { "cubic2p_bspline", "2-parameter cubic (B=1, C=0)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0, FLAGS, "interp_algo" },
555  { "cubic2p_catmullrom", "2-parameter cubic (B=0, C=1/2)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_CATMULLROM }, 0, 0, FLAGS, "interp_algo" },
556  { "cubic2p_b05c03", "2-parameter cubic (B=1/2, C=3/10)", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_B05C03 }, 0, 0, FLAGS, "interp_algo" },
557  { "super", "supersampling", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0, FLAGS, "interp_algo" },
558  { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0, FLAGS, "interp_algo" },
559  { "force_original_aspect_ratio", "decrease or increase w/h if necessary to keep the original AR", OFFSET(force_original_aspect_ratio), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, FLAGS, "force_oar" },
560  { "disable", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 0, FLAGS, "force_oar" },
561  { "decrease", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 0, FLAGS, "force_oar" },
562  { "increase", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 0, FLAGS, "force_oar" },
563  { "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1}, 1, 256, FLAGS },
564  { NULL },
565 };
566 
567 static const AVClass nppscale_class = {
568  .class_name = "nppscale",
569  .item_name = av_default_item_name,
570  .option = options,
571  .version = LIBAVUTIL_VERSION_INT,
572 };
573 
574 static const AVFilterPad nppscale_inputs[] = {
575  {
576  .name = "default",
577  .type = AVMEDIA_TYPE_VIDEO,
578  .filter_frame = nppscale_filter_frame,
579  },
580 };
581 
582 static const AVFilterPad nppscale_outputs[] = {
583  {
584  .name = "default",
585  .type = AVMEDIA_TYPE_VIDEO,
586  .config_props = nppscale_config_props,
587  },
588 };
589 
591  .name = "scale_npp",
592  .description = NULL_IF_CONFIG_SMALL("NVIDIA Performance Primitives video "
593  "scaling and format conversion"),
594 
595  .init = nppscale_init,
596  .uninit = nppscale_uninit,
597  .query_formats = nppscale_query_formats,
598 
599  .priv_size = sizeof(NPPScaleContext),
600  .priv_class = &nppscale_class,
601 
604 
605  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
606 };
format_is_supported
static int format_is_supported(enum AVPixelFormat fmt)
Definition: vf_scale_npp.c:206
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
NPPScaleContext::passthrough
int passthrough
Definition: vf_scale_npp.c:81
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
nppscale_inputs
static const AVFilterPad nppscale_inputs[]
Definition: vf_scale_npp.c:574
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
hwcontext_cuda_internal.h
out
FILE * out
Definition: movenc.c:54
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:334
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2564
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
CHECK_CU
#define CHECK_CU(x)
Definition: vf_scale_npp.c:43
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:209
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
ScaleStage
ScaleStage
Definition: vf_scale_npp.c:55
nppscale_class
static const AVClass nppscale_class
Definition: vf_scale_npp.c:567
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:333
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFrame::width
int width
Definition: frame.h:361
w
uint8_t w
Definition: llviddspenc.c:38
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:247
NPPScaleStageContext::stage_needed
int stage_needed
Definition: vf_scale_npp.c:63
AVOption
AVOption.
Definition: opt.h:247
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: vf_scale_npp.c:45
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_scale_eval_dimensions
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
Definition: scale_eval.c:57
STAGE_NB
@ STAGE_NB
Definition: vf_scale_npp.c:59
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:229
video.h
NPPScaleStageContext::frame
AVFrame * frame
Definition: vf_scale_npp.c:73
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
formats.h
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2604
fail
#define fail()
Definition: checkasm.h:127
get_deinterleaved_format
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
Definition: vf_scale_npp.c:216
STAGE_RESIZE
@ STAGE_RESIZE
Definition: vf_scale_npp.c:57
NPPScaleContext::tmp_frame
AVFrame * tmp_frame
Definition: vf_scale_npp.c:80
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2592
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
NPPScaleContext::shift_width
int shift_width
Definition: vf_scale_npp.c:83
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
planes
static const struct @318 planes[]
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVHWFramesContext::height
int height
Definition: hwcontext.h:229
s
#define s(width, name)
Definition: cbs_vp9.c:257
nppscale_uninit
static void nppscale_uninit(AVFilterContext *ctx)
Definition: vf_scale_npp.c:134
NPPScaleContext::stages
NPPScaleStageContext stages[STAGE_NB]
Definition: vf_scale_npp.c:79
nppscale_query_formats
static int nppscale_query_formats(AVFilterContext *ctx)
Definition: vf_scale_npp.c:146
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:698
ctx
AVFormatContext * ctx
Definition: movenc.c:48
NPPScaleContext::force_original_aspect_ratio
int force_original_aspect_ratio
Definition: vf_scale_npp.c:101
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
NPPScaleContext
Definition: vf_scale_npp.c:76
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_scale_npp.c:544
init_stage
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
Definition: vf_scale_npp.c:154
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
nppscale_interleave
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:433
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:222
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:141
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:354
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
src
#define src
Definition: vp8dsp.c:255
NPPScaleContext::h_expr
char * h_expr
height expression string
Definition: vf_scale_npp.c:98
nppscale_init
static int nppscale_init(AVFilterContext *ctx)
Definition: vf_scale_npp.c:107
NPPScaleContext::shift_height
int shift_height
Definition: vf_scale_npp.c:83
NPPScaleStageContext::height
int height
Definition: vf_scale_npp.c:69
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
NPPScaleStageContext::out_fmt
enum AVPixelFormat out_fmt
Definition: vf_scale_npp.c:65
OFFSET
#define OFFSET(x)
Definition: vf_scale_npp.c:543
NPPScaleStageContext::frames_ctx
AVBufferRef * frames_ctx
Definition: vf_scale_npp.c:72
nppscale_filter_frame
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_npp.c:499
scale_eval.h
nppscale_config_props
static int nppscale_config_props(AVFilterLink *outlink)
Definition: vf_scale_npp.c:337
init_processing_chain
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
Definition: vf_scale_npp.c:230
nppscale_resize
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:405
internal.h
NPPScaleContext::h
int h
Definition: vf_scale_npp.c:90
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
internal.h
ff_vf_scale_npp
const AVFilter ff_vf_scale_npp
Definition: vf_scale_npp.c:590
common.h
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:461
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:437
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
NPPScaleContext::w
int w
New dimensions.
Definition: vf_scale_npp.c:90
AVFilter
Filter definition.
Definition: avfilter.h:149
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
ret
ret
Definition: filter_design.txt:187
NPPScaleContext::format
enum AVPixelFormat format
Output sw format.
Definition: vf_scale_npp.c:95
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
AVClass::class_name
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:71
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:149
cuda_check.h
NPPScaleContext::interp_algo
int interp_algo
Definition: vf_scale_npp.c:104
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:391
ff_scale_adjust_dimensions
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
Definition: scale_eval.c:113
NPPScaleContext::w_expr
char * w_expr
width expression string
Definition: vf_scale_npp.c:97
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2496
NPPScaleStageContext::in_fmt
enum AVPixelFormat in_fmt
Definition: vf_scale_npp.c:64
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:607
AVFrame::height
int height
Definition: frame.h:361
NPPScaleContext::format_str
char * format_str
Definition: vf_scale_npp.c:99
STAGE_INTERLEAVE
@ STAGE_INTERLEAVE
Definition: vf_scale_npp.c:58
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
dummy
int dummy
Definition: motion.c:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
nppscale_process
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:458
nppscale_outputs
static const AVFilterPad nppscale_outputs[]
Definition: vf_scale_npp.c:582
NPPScaleContext::force_divisible_by
int force_divisible_by
Definition: vf_scale_npp.c:102
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
NPPScaleStageContext::width
int width
Definition: vf_scale_npp.c:68
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
NPPScaleStageContext
Definition: vf_scale_npp.c:62
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
STAGE_DEINTERLEAVE
@ STAGE_DEINTERLEAVE
Definition: vf_scale_npp.c:56
NPPScaleStageContext::planes_out
struct NPPScaleStageContext::@231 planes_out[3]
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
options
static const AVOption options[]
Definition: vf_scale_npp.c:545
nppscale_deinterleave
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:381
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
deinterleaved_formats
static enum AVPixelFormat deinterleaved_formats[][2]
Definition: vf_scale_npp.c:51
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
NPPScaleStageContext::planes_in
struct NPPScaleStageContext::@231 planes_in[3]
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
int
int
Definition: ffmpeg_filter.c:156
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:502
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2484
nppscale_scale
static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_scale_npp.c:465