FFmpeg
vf_chromakey_cuda.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Mohamed Khaled <Mohamed_Khaled_Kamal@outlook.com>
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 #include <float.h>
22 #include <stdio.h>
23 
24 #include "libavutil/common.h"
25 #include "libavutil/hwcontext.h"
27 #include "libavutil/cuda_check.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixdesc.h"
31 
32 #include "avfilter.h"
33 #include "filters.h"
34 #include "cuda/load_helper.h"
35 #include "video.h"
36 
37 static const enum AVPixelFormat supported_formats[] = {
41 };
42 
43 #define DIV_UP(a, b) (((a) + (b)-1) / (b))
44 #define BLOCKX 32
45 #define BLOCKY 16
46 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
47 
48 typedef struct ChromakeyCUDAContext {
49  const AVClass *class;
50 
52 
53  enum AVPixelFormat in_fmt, out_fmt;
58 
59  uint8_t chromakey_rgba[4];
60  uint16_t chromakey_uv[2];
61  int is_yuv;
62  float similarity;
63  float blend;
64 
65  CUcontext cu_ctx;
66  CUmodule cu_module;
67  CUfunction cu_func;
68  CUfunction cu_func_uv;
69  CUstream cu_stream;
71 
73 {
74  ChromakeyCUDAContext *s = ctx->priv;
75 
76  if (s->hwctx && s->cu_module)
77  {
78  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
79  CUcontext context;
80 
81  CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
82  CHECK_CU(cu->cuModuleUnload(s->cu_module));
83  s->cu_module = NULL;
84  CHECK_CU(cu->cuCtxPopCurrent(&context));
85  }
86 }
87 
88 static av_cold int init_hwframe_ctx(AVFilterContext *ctx, AVBufferRef *device_ctx, int width, int height)
89 {
90  FilterLink *outl = ff_filter_link(ctx->outputs[0]);
91  ChromakeyCUDAContext *s = ctx->priv;
92  AVBufferRef *out_ref = NULL;
93  AVHWFramesContext *out_ctx;
94  int ret;
95 
96  out_ref = av_hwframe_ctx_alloc(device_ctx);
97  if (!out_ref)
98  return AVERROR(ENOMEM);
99  out_ctx = (AVHWFramesContext *)out_ref->data;
100 
101  out_ctx->format = AV_PIX_FMT_CUDA;
102  out_ctx->sw_format = s->out_fmt;
103  out_ctx->width = width;
104  out_ctx->height = height;
105 
106  ret = av_hwframe_ctx_init(out_ref);
107  if (ret < 0)
108  goto fail;
109 
110  outl->hw_frames_ctx = out_ref;
111 
112  return 0;
113 fail:
114  av_buffer_unref(&out_ref);
115  return ret;
116 }
117 
118 static int format_is_supported(enum AVPixelFormat fmt)
119 {
120  int i;
121 
122  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
123  if (supported_formats[i] == fmt)
124  return 1;
125  return 0;
126 }
127 
128 static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
129 {
130  ChromakeyCUDAContext *s = ctx->priv;
131  int i, p, d;
132 
133  s->in_fmt = in_format;
134  s->out_fmt = out_format;
135 
136  s->in_desc = av_pix_fmt_desc_get(s->in_fmt);
137  s->out_desc = av_pix_fmt_desc_get(s->out_fmt);
138  s->in_planes = av_pix_fmt_count_planes(s->in_fmt);
139  s->out_planes = av_pix_fmt_count_planes(s->out_fmt);
140 
141  // find maximum step of each component of each plane
142  // For our subset of formats, this should accurately tell us how many channels CUDA needs
143  // i.e. 1 for Y plane, 2 for UV plane of NV12, 4 for single plane of RGB0 formats
144 
145  for (i = 0; i < s->in_desc->nb_components; i++)
146  {
147  d = (s->in_desc->comp[i].depth + 7) / 8;
148  p = s->in_desc->comp[i].plane;
149  s->in_plane_channels[p] = FFMAX(s->in_plane_channels[p], s->in_desc->comp[i].step / d);
150 
151  s->in_plane_depths[p] = s->in_desc->comp[i].depth;
152  }
153 }
154 
156 {
157  FilterLink *inl = ff_filter_link(ctx->inputs[0]);
158  ChromakeyCUDAContext *s = ctx->priv;
159  AVHWFramesContext *in_frames_ctx;
160  int ret;
161 
162  /* check that we have a hw context */
163  if (!inl->hw_frames_ctx) {
164  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
165  return AVERROR(EINVAL);
166  }
167  in_frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
168 
169  if (!format_is_supported(in_frames_ctx->sw_format))
170  {
171  av_log(ctx, AV_LOG_ERROR, "Unsupported format: %s\n", av_get_pix_fmt_name(in_frames_ctx->sw_format));
172  return AVERROR(ENOSYS);
173  }
174 
176 
177  if (in_frames_ctx->sw_format == s->out_fmt) {
179  if (!ff_filter_link(ctx->outputs[0])->hw_frames_ctx)
180  return AVERROR(ENOMEM);
181  } else {
182  ret = init_hwframe_ctx(ctx, in_frames_ctx->device_ref, width, height);
183  if (ret < 0)
184  return ret;
185  }
186 
187  return 0;
188 }
189 
191 {
192  ChromakeyCUDAContext *s = ctx->priv;
193  CUcontext context, cuda_ctx = s->hwctx->cuda_ctx;
194  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
195  int ret;
196 
197  extern const unsigned char ff_vf_chromakey_cuda_ptx_data[];
198  extern const unsigned int ff_vf_chromakey_cuda_ptx_len;
199 
200  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
201  if (ret < 0)
202  return ret;
203 
204  ret = ff_cuda_load_module(ctx, s->hwctx, &s->cu_module,
205  ff_vf_chromakey_cuda_ptx_data, ff_vf_chromakey_cuda_ptx_len);
206  if (ret < 0)
207  goto fail;
208 
209  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func, s->cu_module, "Process_uchar"));
210  if (ret < 0)
211  {
212  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar\n");
213  goto fail;
214  }
215 
216  ret = CHECK_CU(cu->cuModuleGetFunction(&s->cu_func_uv, s->cu_module, "Process_uchar2"));
217  if (ret < 0)
218  {
219  av_log(ctx, AV_LOG_FATAL, "Failed loading Process_uchar2\n");
220  goto fail;
221  }
222 
223 fail:
224  CHECK_CU(cu->cuCtxPopCurrent(&context));
225 
226  return ret;
227 }
228 
229 #define FIXNUM(x) lrint((x) * (1 << 10))
230 #define RGB_TO_U(rgb) (((-FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
231 #define RGB_TO_V(rgb) (((FIXNUM(0.50000) * rgb[0] - FIXNUM(0.41869) * rgb[1] - FIXNUM(0.08131) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
232 
234 {
235  AVFilterContext *ctx = outlink->src;
236  AVFilterLink *inlink = outlink->src->inputs[0];
238  ChromakeyCUDAContext *s = ctx->priv;
239  AVHWFramesContext *frames_ctx;
240  AVCUDADeviceContext *device_hwctx;
241  int ret;
242 
243  if (s->is_yuv) {
244  s->chromakey_uv[0] = s->chromakey_rgba[1];
245  s->chromakey_uv[1] = s->chromakey_rgba[2];
246  } else {
247  s->chromakey_uv[0] = RGB_TO_U(s->chromakey_rgba);
248  s->chromakey_uv[1] = RGB_TO_V(s->chromakey_rgba);
249  }
250 
252  if (ret < 0)
253  return ret;
254 
255  frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
256  device_hwctx = frames_ctx->device_ctx->hwctx;
257 
258  s->hwctx = device_hwctx;
259  s->cu_stream = s->hwctx->stream;
260 
261  outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
263 
265  if (ret < 0)
266  return ret;
267 
268  return 0;
269 }
270 
271 static int call_cuda_kernel(AVFilterContext *ctx, CUfunction func,
272  CUtexObject src_tex[3], AVFrame *out_frame,
273  int width, int height, int pitch,
274  int width_uv, int height_uv, int pitch_uv,
275  float u_key, float v_key, float similarity,
276  float blend)
277 {
278  ChromakeyCUDAContext *s = ctx->priv;
279  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
280 
281  CUdeviceptr dst_devptr[4] = {
282  (CUdeviceptr)out_frame->data[0], (CUdeviceptr)out_frame->data[1],
283  (CUdeviceptr)out_frame->data[2], (CUdeviceptr)out_frame->data[3]
284  };
285 
286  void *args_uchar[] = {
287  &src_tex[0], &src_tex[1], &src_tex[2],
288  &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
289  &width, &height, &pitch,
290  &width_uv, &height_uv, &pitch_uv,
291  &u_key, &v_key, &similarity, &blend
292  };
293 
294  return CHECK_CU(cu->cuLaunchKernel(func,
296  BLOCKX, BLOCKY, 1, 0, s->cu_stream, args_uchar, NULL));
297 }
298 
300  AVFrame *out, AVFrame *in)
301 {
302  ChromakeyCUDAContext *s = ctx->priv;
303  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
304  CUcontext context, cuda_ctx = s->hwctx->cuda_ctx;
305  int i, ret;
306 
307  CUtexObject tex[3] = {0, 0, 0};
308 
309  ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
310  if (ret < 0)
311  return ret;
312 
313  for (i = 0; i < s->in_planes; i++)
314  {
315  CUDA_TEXTURE_DESC tex_desc = {
316  .filterMode = CU_TR_FILTER_MODE_LINEAR,
317  .flags = 0, // CU_TRSF_READ_AS_INTEGER to get raw ints instead of normalized floats from tex2D
318  };
319 
320  CUDA_RESOURCE_DESC res_desc = {
321  .resType = CU_RESOURCE_TYPE_PITCH2D,
322  .res.pitch2D.format = CU_AD_FORMAT_UNSIGNED_INT8,
323  .res.pitch2D.numChannels = s->in_plane_channels[i],
324  .res.pitch2D.pitchInBytes = in->linesize[i],
325  .res.pitch2D.devPtr = (CUdeviceptr)in->data[i],
326  };
327 
328  if (i == 1 || i == 2)
329  {
330  res_desc.res.pitch2D.width = AV_CEIL_RSHIFT(in->width, s->in_desc->log2_chroma_w);
331  res_desc.res.pitch2D.height = AV_CEIL_RSHIFT(in->height, s->in_desc->log2_chroma_h);
332  }
333  else
334  {
335  res_desc.res.pitch2D.width = in->width;
336  res_desc.res.pitch2D.height = in->height;
337  }
338 
339  ret = CHECK_CU(cu->cuTexObjectCreate(&tex[i], &res_desc, &tex_desc, NULL));
340  if (ret < 0)
341  goto exit;
342  }
343 
344  ret = call_cuda_kernel(ctx, (s->in_plane_channels[1] > 1) ? s->cu_func_uv : s->cu_func,
345  tex, out,
346  out->width, out->height, out->linesize[0],
347  AV_CEIL_RSHIFT(out->width, s->out_desc->log2_chroma_w),
348  AV_CEIL_RSHIFT(out->height, s->out_desc->log2_chroma_h),
349  out->linesize[1],
350  s->chromakey_uv[0], s->chromakey_uv[1],
351  s->similarity, s->blend);
352  if (ret < 0)
353  goto exit;
354 
355 exit:
356  for (i = 0; i < s->in_planes; i++)
357  if (tex[i])
358  CHECK_CU(cu->cuTexObjectDestroy(tex[i]));
359 
360  CHECK_CU(cu->cuCtxPopCurrent(&context));
361 
362  return ret;
363 }
364 
366 {
367  AVFilterContext *ctx = link->dst;
368  ChromakeyCUDAContext *s = ctx->priv;
369  AVFilterLink *outlink = ctx->outputs[0];
370  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
371 
372  AVFrame *out;
373  CUcontext context;
374  int ret = 0;
375 
376  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
377  if (!out) {
378  ret = AVERROR(ENOMEM);
379  goto fail;
380  }
381 
382  ret = CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
383  if (ret < 0)
384  goto fail;
385 
387  if (ret < 0)
388  goto fail;
389 
390  ret = av_frame_copy_props(out, in);
391  if (ret < 0)
392  goto fail;
393  out->alpha_mode = outlink->alpha_mode;
394 
395  ret = CHECK_CU(cu->cuCtxPopCurrent(&context));
396  if (ret < 0)
397  goto fail;
398 
399  av_frame_free(&in);
400  return ff_filter_frame(outlink, out);
401 fail:
402  av_frame_free(&in);
403  av_frame_free(&out);
404  return ret;
405 }
406 
407 #define OFFSET(x) offsetof(ChromakeyCUDAContext, x)
408 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
409 static const AVOption options[] = {
410  {"color", "set the chromakey key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS},
411  {"similarity", "set the chromakey similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, {.dbl = 0.01}, 0.01, 1.0, FLAGS},
412  {"blend", "set the chromakey key blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, FLAGS},
413  {"yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
414  {NULL},
415 };
416 
417 static const AVClass cudachromakey_class = {
418  .class_name = "cudachromakey",
419  .item_name = av_default_item_name,
420  .option = options,
421  .version = LIBAVUTIL_VERSION_INT,
422 };
423 
425  {
426  .name = "default",
427  .type = AVMEDIA_TYPE_VIDEO,
428  .filter_frame = cudachromakey_filter_frame,
429  },
430 };
431 
433  {
434  .name = "default",
435  .type = AVMEDIA_TYPE_VIDEO,
436  .config_props = cudachromakey_config_props,
437  },
438 };
439 
441  .p.name = "chromakey_cuda",
442  .p.description = NULL_IF_CONFIG_SMALL("GPU accelerated chromakey filter"),
443 
444  .p.priv_class = &cudachromakey_class,
445  .uninit = cudachromakey_uninit,
446  .priv_size = sizeof(ChromakeyCUDAContext),
447 
450 
452 
453  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
454 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:117
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:68
ChromakeyCUDAContext
Definition: vf_chromakey_cuda.c:48
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:88
call_cuda_kernel
static int call_cuda_kernel(AVFilterContext *ctx, CUfunction func, CUtexObject src_tex[3], AVFrame *out_frame, int width, int height, int pitch, int width_uv, int height_uv, int pitch_uv, float u_key, float v_key, float similarity, float blend)
Definition: vf_chromakey_cuda.c:271
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: vf_chromakey_cuda.c:37
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
AVALPHA_MODE_STRAIGHT
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition: pixfmt.h:803
hwcontext_cuda_internal.h
out
FILE * out
Definition: movenc.c:55
ChromakeyCUDAContext::in_desc
const AVPixFmtDescriptor * in_desc
Definition: vf_chromakey_cuda.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1067
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3447
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:200
ff_cuda_load_module
int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module, const unsigned char *data, const unsigned int length)
Loads a CUDA module and applies any decompression, if necessary.
Definition: load_helper.c:35
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
pixdesc.h
AVFrame::width
int width
Definition: frame.h:499
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:263
AVOption
AVOption.
Definition: opt.h:429
ChromakeyCUDAContext::cu_func_uv
CUfunction cu_func_uv
Definition: vf_chromakey_cuda.c:68
ChromakeyCUDAContext::chromakey_rgba
uint8_t chromakey_rgba[4]
Definition: vf_chromakey_cuda.c:59
float.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
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:220
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:220
video.h
DIV_UP
#define DIV_UP(a, b)
Definition: vf_chromakey_cuda.c:43
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:448
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3487
fail
#define fail()
Definition: checkasm.h:206
cudachromakey_load_functions
static av_cold int cudachromakey_load_functions(AVFilterContext *ctx)
Definition: vf_chromakey_cuda.c:190
ChromakeyCUDAContext::is_yuv
int is_yuv
Definition: vf_chromakey_cuda.c:61
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
ChromakeyCUDAContext::cu_ctx
CUcontext cu_ctx
Definition: vf_chromakey_cuda.c:65
FLAGS
#define FLAGS
Definition: vf_chromakey_cuda.c:408
BLOCKY
#define BLOCKY
Definition: vf_chromakey_cuda.c:45
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:106
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
FFFilter
Definition: filters.h:266
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
ChromakeyCUDAContext::cu_stream
CUstream cu_stream
Definition: vf_chromakey_cuda.c:69
ChromakeyCUDAContext::in_plane_depths
int in_plane_depths[4]
Definition: vf_chromakey_cuda.c:56
RGB_TO_U
#define RGB_TO_U(rgb)
Definition: vf_chromakey_cuda.c:230
ChromakeyCUDAContext::blend
float blend
Definition: vf_chromakey_cuda.c:63
filters.h
options
static const AVOption options[]
Definition: vf_chromakey_cuda.c:409
init_hwframe_ctx
static av_cold int init_hwframe_ctx(AVFilterContext *ctx, AVBufferRef *device_ctx, int width, int height)
Definition: vf_chromakey_cuda.c:88
ctx
AVFormatContext * ctx
Definition: movenc.c:49
cudachromakey_uninit
static av_cold void cudachromakey_uninit(AVFilterContext *ctx)
Definition: vf_chromakey_cuda.c:72
OFFSET
#define OFFSET(x)
Definition: vf_chromakey_cuda.c:407
load_helper.h
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:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
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
if
if(ret)
Definition: filter_design.txt:179
context
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
init_processing_chain
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
Definition: vf_chromakey_cuda.c:155
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:213
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:599
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
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:129
ChromakeyCUDAContext::cu_func
CUfunction cu_func
Definition: vf_chromakey_cuda.c:67
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:282
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:241
options
Definition: swscale.c:43
ChromakeyCUDAContext::hwctx
AVCUDADeviceContext * hwctx
Definition: vf_chromakey_cuda.c:51
ChromakeyCUDAContext::out_fmt
enum AVPixelFormat in_fmt out_fmt
Definition: vf_chromakey_cuda.c:53
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:198
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:207
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:94
height
#define height
Definition: dsp.h:89
ChromakeyCUDAContext::out_desc
const AVPixFmtDescriptor * out_desc
Definition: vf_chromakey_cuda.c:54
ChromakeyCUDAContext::similarity
float similarity
Definition: vf_chromakey_cuda.c:62
ChromakeyCUDAContext::in_plane_channels
int in_plane_channels[4]
Definition: vf_chromakey_cuda.c:57
ChromakeyCUDAContext::out_planes
int out_planes
Definition: vf_chromakey_cuda.c:55
RGB_TO_V
#define RGB_TO_V(rgb)
Definition: vf_chromakey_cuda.c:231
ChromakeyCUDAContext::chromakey_uv
uint16_t chromakey_uv[2]
Definition: vf_chromakey_cuda.c:60
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
ChromakeyCUDAContext::cu_module
CUmodule cu_module
Definition: vf_chromakey_cuda.c:66
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
internal.h
cudachromakey_class
static const AVClass cudachromakey_class
Definition: vf_chromakey_cuda.c:417
common.h
set_format_info
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
Definition: vf_chromakey_cuda.c:128
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
format_is_supported
static int format_is_supported(enum AVPixelFormat fmt)
Definition: vf_chromakey_cuda.c:118
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:204
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:96
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:81
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:137
cuda_check.h
cudachromakey_outputs
static const AVFilterPad cudachromakey_outputs[]
Definition: vf_chromakey_cuda.c:432
AVFrame::height
int height
Definition: frame.h:499
avfilter.h
cudachromakey_filter_frame
static int cudachromakey_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_chromakey_cuda.c:365
cudachromakey_inputs
static const AVFilterPad cudachromakey_inputs[]
Definition: vf_chromakey_cuda.c:424
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
BLOCKX
#define BLOCKX
Definition: vf_chromakey_cuda.c:44
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
ChromakeyCUDAContext::in_planes
int in_planes
Definition: vf_chromakey_cuda.c:55
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
cudachromakey_process_internal
static int cudachromakey_process_internal(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
Definition: vf_chromakey_cuda.c:299
cudachromakey_config_props
static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
Definition: vf_chromakey_cuda.c:233
CHECK_CU
#define CHECK_CU(x)
Definition: vf_chromakey_cuda.c:46
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
ff_vf_chromakey_cuda
const FFFilter ff_vf_chromakey_cuda
Definition: vf_chromakey_cuda.c:440
hwcontext.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:472
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
width
#define width
Definition: dsp.h:89
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:253
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:3367