FFmpeg
Data Structures | Macros | Functions | Variables
vf_chromakey_cuda.c File Reference
#include <float.h>
#include <stdio.h>
#include "libavutil/common.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/cuda_check.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "cuda/load_helper.h"

Go to the source code of this file.

Data Structures

struct  ChromakeyCUDAContext
 

Macros

#define DIV_UP(a, b)   (((a) + (b)-1) / (b))
 
#define BLOCKX   32
 
#define BLOCKY   16
 
#define CHECK_CU(x)   FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
 
#define FIXNUM(x)   lrint((x) * (1 << 10))
 
#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)
 
#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)
 
#define OFFSET(x)   offsetof(ChromakeyCUDAContext, x)
 
#define FLAGS   (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
 

Functions

static av_cold int cudachromakey_init (AVFilterContext *ctx)
 
static av_cold void cudachromakey_uninit (AVFilterContext *ctx)
 
static av_cold int init_hwframe_ctx (ChromakeyCUDAContext *s, AVBufferRef *device_ctx, int width, int height)
 
static int format_is_supported (enum AVPixelFormat fmt)
 
static av_cold void set_format_info (AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
 
static av_cold int init_processing_chain (AVFilterContext *ctx, int width, int height)
 
static av_cold int cudachromakey_load_functions (AVFilterContext *ctx)
 
static av_cold int cudachromakey_config_props (AVFilterLink *outlink)
 
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)
 
static int cudachromakey_process_internal (AVFilterContext *ctx, AVFrame *out, AVFrame *in)
 
static int cudachromakey_process (AVFilterContext *ctx, AVFrame *out, AVFrame *in)
 
static int cudachromakey_filter_frame (AVFilterLink *link, AVFrame *in)
 

Variables

static enum AVPixelFormat supported_formats []
 
static const AVOption options []
 
static const AVClass cudachromakey_class
 
static const AVFilterPad cudachromakey_inputs []
 
static const AVFilterPad cudachromakey_outputs []
 
const AVFilter ff_vf_chromakey_cuda
 

Macro Definition Documentation

◆ DIV_UP

#define DIV_UP (   a,
  b 
)    (((a) + (b)-1) / (b))

Definition at line 42 of file vf_chromakey_cuda.c.

◆ BLOCKX

#define BLOCKX   32

Definition at line 43 of file vf_chromakey_cuda.c.

◆ BLOCKY

#define BLOCKY   16

Definition at line 44 of file vf_chromakey_cuda.c.

◆ CHECK_CU

#define CHECK_CU (   x)    FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)

Definition at line 45 of file vf_chromakey_cuda.c.

◆ FIXNUM

#define FIXNUM (   x)    lrint((x) * (1 << 10))

Definition at line 254 of file vf_chromakey_cuda.c.

◆ RGB_TO_U

#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)

Definition at line 255 of file vf_chromakey_cuda.c.

◆ RGB_TO_V

#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)

Definition at line 256 of file vf_chromakey_cuda.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(ChromakeyCUDAContext, x)

Definition at line 450 of file vf_chromakey_cuda.c.

◆ FLAGS

Definition at line 451 of file vf_chromakey_cuda.c.

Function Documentation

◆ cudachromakey_init()

static av_cold int cudachromakey_init ( AVFilterContext ctx)
static

Definition at line 75 of file vf_chromakey_cuda.c.

◆ cudachromakey_uninit()

static av_cold void cudachromakey_uninit ( AVFilterContext ctx)
static

Definition at line 90 of file vf_chromakey_cuda.c.

◆ init_hwframe_ctx()

static av_cold int init_hwframe_ctx ( ChromakeyCUDAContext s,
AVBufferRef device_ctx,
int  width,
int  height 
)
static

Definition at line 110 of file vf_chromakey_cuda.c.

Referenced by init_processing_chain().

◆ format_is_supported()

static int format_is_supported ( enum AVPixelFormat  fmt)
static

Definition at line 144 of file vf_chromakey_cuda.c.

Referenced by init_processing_chain().

◆ set_format_info()

static av_cold void set_format_info ( AVFilterContext ctx,
enum AVPixelFormat  in_format,
enum AVPixelFormat  out_format 
)
static

Definition at line 154 of file vf_chromakey_cuda.c.

Referenced by init_processing_chain().

◆ init_processing_chain()

static av_cold int init_processing_chain ( AVFilterContext ctx,
int  width,
int  height 
)
static

Definition at line 181 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_config_props().

◆ cudachromakey_load_functions()

static av_cold int cudachromakey_load_functions ( AVFilterContext ctx)
static

Definition at line 215 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_config_props().

◆ cudachromakey_config_props()

static av_cold int cudachromakey_config_props ( AVFilterLink outlink)
static

Definition at line 258 of file vf_chromakey_cuda.c.

◆ 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 
)
static

Definition at line 295 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_process_internal().

◆ cudachromakey_process_internal()

static int cudachromakey_process_internal ( AVFilterContext ctx,
AVFrame out,
AVFrame in 
)
static

Definition at line 323 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_process().

◆ cudachromakey_process()

static int cudachromakey_process ( AVFilterContext ctx,
AVFrame out,
AVFrame in 
)
static

Definition at line 389 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_filter_frame().

◆ cudachromakey_filter_frame()

static int cudachromakey_filter_frame ( AVFilterLink link,
AVFrame in 
)
static

Definition at line 414 of file vf_chromakey_cuda.c.

Variable Documentation

◆ supported_formats

enum AVPixelFormat supported_formats[]
static
Initial value:

Definition at line 36 of file vf_chromakey_cuda.c.

Referenced by format_is_supported().

◆ options

const AVOption options[]
static
Initial value:
= {
{"color", "set the chromakey key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, {.str = "black"}, 0, 0, FLAGS},
{"similarity", "set the chromakey similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, {.dbl = 0.01}, 0.01, 1.0, FLAGS},
{"blend", "set the chromakey key blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, FLAGS},
{"yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
{NULL},
}

Definition at line 452 of file vf_chromakey_cuda.c.

◆ cudachromakey_class

const AVClass cudachromakey_class
static
Initial value:
= {
.class_name = "cudachromakey",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 460 of file vf_chromakey_cuda.c.

◆ cudachromakey_inputs

const AVFilterPad cudachromakey_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = cudachromakey_filter_frame,
},
}

Definition at line 467 of file vf_chromakey_cuda.c.

◆ cudachromakey_outputs

const AVFilterPad cudachromakey_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = cudachromakey_config_props,
},
}

Definition at line 475 of file vf_chromakey_cuda.c.

◆ ff_vf_chromakey_cuda

const AVFilter ff_vf_chromakey_cuda
Initial value:
= {
.name = "chromakey_cuda",
.description = NULL_IF_CONFIG_SMALL("GPU accelerated chromakey filter"),
.priv_size = sizeof(ChromakeyCUDAContext),
.priv_class = &cudachromakey_class,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}

Definition at line 483 of file vf_chromakey_cuda.c.

ChromakeyCUDAContext
Definition: vf_chromakey_cuda.c:47
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
FLAGS
#define FLAGS
Definition: vf_chromakey_cuda.c:451
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
options
static const AVOption options[]
Definition: vf_chromakey_cuda.c:452
cudachromakey_uninit
static av_cold void cudachromakey_uninit(AVFilterContext *ctx)
Definition: vf_chromakey_cuda.c:90
OFFSET
#define OFFSET(x)
Definition: vf_chromakey_cuda.c:450
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:263
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition: opt.h:323
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
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:206
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
cudachromakey_init
static av_cold int cudachromakey_init(AVFilterContext *ctx)
Definition: vf_chromakey_cuda.c:75
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
cudachromakey_class
static const AVClass cudachromakey_class
Definition: vf_chromakey_cuda.c:460
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
cudachromakey_outputs
static const AVFilterPad cudachromakey_outputs[]
Definition: vf_chromakey_cuda.c:475
cudachromakey_filter_frame
static int cudachromakey_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_chromakey_cuda.c:414
cudachromakey_inputs
static const AVFilterPad cudachromakey_inputs[]
Definition: vf_chromakey_cuda.c:467
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
cudachromakey_config_props
static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
Definition: vf_chromakey_cuda.c:258
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252