FFmpeg
Loading...
Searching...
No Matches
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"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ChromakeyCUDAContext
 

Macros

#define DIV_UP(a, b)
 
#define BLOCKX   32
 
#define BLOCKY   16
 
#define CHECK_CU(x)
 
#define FIXNUM(x)
 
#define RGB_TO_U(rgb)
 
#define RGB_TO_V(rgb)
 
#define OFFSET(x)
 
#define FLAGS   (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
 

Functions

static av_cold void cudachromakey_uninit (AVFilterContext *ctx)
 
static av_cold int init_hwframe_ctx (AVFilterContext *ctx, 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_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 FFFilter ff_vf_chromakey_cuda
 

Macro Definition Documentation

◆ DIV_UP

#define DIV_UP ( a,
b )
Value:
(((a) + (b)-1) / (b))
int a
#define b
Definition input.c:43

Definition at line 43 of file vf_chromakey_cuda.c.

Referenced by call_cuda_kernel().

◆ BLOCKX

#define BLOCKX   32

Definition at line 44 of file vf_chromakey_cuda.c.

◆ BLOCKY

#define BLOCKY   16

Definition at line 45 of file vf_chromakey_cuda.c.

◆ CHECK_CU

#define CHECK_CU ( x)
Value:
FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
static AVFormatContext * ctx
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CUDA_CHECK_DL(avclass, cudl, x)
Convenience wrapper for ff_cuda_check when dynamically loading cuda symbols.
Definition cuda_check.h:65

Definition at line 46 of file vf_chromakey_cuda.c.

Referenced by call_cuda_kernel(), cudachromakey_filter_frame(), cudachromakey_load_functions(), cudachromakey_process_internal(), and cudachromakey_uninit().

◆ FIXNUM

#define FIXNUM ( x)
Value:
lrint((x) * (1 << 10))
#define lrint
Definition tablegen.h:53

Definition at line 229 of file vf_chromakey_cuda.c.

◆ RGB_TO_U

#define RGB_TO_U ( rgb)
Value:
(((-FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
Definition rpzaenc.c:60
#define FIXNUM(x)

Definition at line 230 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_config_props().

◆ RGB_TO_V

#define RGB_TO_V ( rgb)
Value:
(((FIXNUM(0.50000) * rgb[0] - FIXNUM(0.41869) * rgb[1] - FIXNUM(0.08131) * rgb[2] + (1 << 9) - 1) >> 10) + 128)

Definition at line 231 of file vf_chromakey_cuda.c.

Referenced by cudachromakey_config_props().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 407 of file vf_chromakey_cuda.c.

◆ FLAGS

Definition at line 408 of file vf_chromakey_cuda.c.

Function Documentation

◆ cudachromakey_uninit()

static av_cold void cudachromakey_uninit ( AVFilterContext * ctx)
static

Definition at line 72 of file vf_chromakey_cuda.c.

◆ init_hwframe_ctx()

static av_cold int init_hwframe_ctx ( AVFilterContext * ctx,
AVBufferRef * device_ctx,
int width,
int height )
static

Definition at line 88 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 118 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 128 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 155 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 190 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 233 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 271 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 299 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 365 of file vf_chromakey_cuda.c.

Variable Documentation

◆ supported_formats

enum AVPixelFormat supported_formats[]
static
Initial value:
= {
}
@ 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
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108

Definition at line 37 of file vf_chromakey_cuda.c.

◆ 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},
}
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition opt.h:322

Definition at line 409 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,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 417 of file vf_chromakey_cuda.c.

◆ cudachromakey_inputs

const AVFilterPad cudachromakey_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = cudachromakey_filter_frame,
},
}
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int cudachromakey_filter_frame(AVFilterLink *link, AVFrame *in)

Definition at line 424 of file vf_chromakey_cuda.c.

◆ cudachromakey_outputs

const AVFilterPad cudachromakey_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = cudachromakey_config_props,
},
}
static av_cold int cudachromakey_config_props(AVFilterLink *outlink)

Definition at line 432 of file vf_chromakey_cuda.c.

◆ ff_vf_chromakey_cuda

const FFFilter ff_vf_chromakey_cuda
Initial value:
= {
.p.name = "chromakey_cuda",
.p.description = NULL_IF_CONFIG_SMALL("GPU accelerated chromakey filter"),
.p.priv_class = &cudachromakey_class,
.priv_size = sizeof(ChromakeyCUDAContext),
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#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:208
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition filters.h:254
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
static const AVFilterPad cudachromakey_inputs[]
static const AVClass cudachromakey_class
static const AVFilterPad cudachromakey_outputs[]
static av_cold void cudachromakey_uninit(AVFilterContext *ctx)

Definition at line 440 of file vf_chromakey_cuda.c.