Go to the documentation of this file.
42 #define DIV_UP(a, b) (((a) + (b)-1) / (b))
45 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
94 if (
s->hwctx &&
s->cu_module)
96 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
99 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
100 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
136 s->frames_ctx = out_ref;
159 s->in_fmt = in_format;
160 s->out_fmt = out_format;
171 for (
i = 0;
i <
s->in_desc->nb_components;
i++)
173 d = (
s->in_desc->comp[
i].depth + 7) / 8;
174 p =
s->in_desc->comp[
i].plane;
175 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step / d);
177 s->in_plane_depths[p] =
s->in_desc->comp[
i].depth;
218 CUcontext
context, cuda_ctx =
s->hwctx->cuda_ctx;
219 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
222 extern const unsigned char ff_vf_chromakey_cuda_ptx_data[];
223 extern const unsigned int ff_vf_chromakey_cuda_ptx_len;
230 ff_vf_chromakey_cuda_ptx_data, ff_vf_chromakey_cuda_ptx_len);
234 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func,
s->cu_module,
"Process_uchar"));
241 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_uv,
s->cu_module,
"Process_uchar2"));
254 #define FIXNUM(x) lrint((x) * (1 << 10))
255 #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)
256 #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)
269 s->chromakey_uv[0] =
s->chromakey_rgba[1];
270 s->chromakey_uv[1] =
s->chromakey_rgba[2];
272 s->chromakey_uv[0] =
RGB_TO_U(
s->chromakey_rgba);
273 s->chromakey_uv[1] =
RGB_TO_V(
s->chromakey_rgba);
283 s->hwctx = device_hwctx;
284 s->cu_stream =
s->hwctx->stream;
296 CUtexObject src_tex[3],
AVFrame *out_frame,
298 int width_uv,
int height_uv,
int pitch_uv,
299 float u_key,
float v_key,
float similarity,
303 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
305 CUdeviceptr dst_devptr[4] = {
306 (CUdeviceptr)out_frame->
data[0], (CUdeviceptr)out_frame->
data[1],
307 (CUdeviceptr)out_frame->
data[2], (CUdeviceptr)out_frame->
data[3]
310 void *args_uchar[] = {
311 &src_tex[0], &src_tex[1], &src_tex[2],
312 &dst_devptr[0], &dst_devptr[1], &dst_devptr[2], &dst_devptr[3],
314 &width_uv, &height_uv, &pitch_uv,
315 &u_key, &v_key, &similarity, &blend
327 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
328 CUcontext
context, cuda_ctx =
s->hwctx->cuda_ctx;
331 CUtexObject tex[3] = {0, 0, 0};
337 for (
i = 0;
i <
s->in_planes;
i++)
339 CUDA_TEXTURE_DESC tex_desc = {
340 .filterMode = CU_TR_FILTER_MODE_LINEAR,
344 CUDA_RESOURCE_DESC res_desc = {
345 .resType = CU_RESOURCE_TYPE_PITCH2D,
346 .res.pitch2D.format = CU_AD_FORMAT_UNSIGNED_INT8,
347 .res.pitch2D.numChannels =
s->in_plane_channels[
i],
348 .res.pitch2D.pitchInBytes = in->
linesize[
i],
349 .res.pitch2D.devPtr = (CUdeviceptr)in->
data[
i],
352 if (
i == 1 ||
i == 2)
359 res_desc.res.pitch2D.width = in->
width;
360 res_desc.res.pitch2D.height = in->
height;
370 out->width,
out->height,
out->linesize[0],
374 s->chromakey_uv[0],
s->chromakey_uv[1],
375 s->similarity,
s->blend);
380 for (
i = 0;
i <
s->in_planes;
i++)
382 CHECK_CU(cu->cuTexObjectDestroy(tex[
i]));
419 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
432 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
450 #define OFFSET(x) offsetof(ChromakeyCUDAContext, x)
451 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
484 .
name =
"chromakey_cuda",
int(* func)(AVBPrint *dst, const char *in, const char *arg)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
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)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static enum AVPixelFormat supported_formats[]
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
const AVPixFmtDescriptor * in_desc
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
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.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
uint8_t chromakey_rgba[4]
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static av_cold int cudachromakey_load_functions(AVFilterContext *ctx)
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, b)
const AVFilter ff_vf_chromakey_cuda
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static const AVOption options[]
static av_cold void cudachromakey_uninit(AVFilterContext *ctx)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_OUTPUTS(array)
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
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
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
AVCUDADeviceContext * hwctx
enum AVPixelFormat in_fmt out_fmt
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const AVPixFmtDescriptor * out_desc
static av_cold int init_hwframe_ctx(ChromakeyCUDAContext *s, AVBufferRef *device_ctx, int width, int height)
static av_cold int cudachromakey_init(AVFilterContext *ctx)
AVFilterContext * src
source filter
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
#define i(width, name, range_min, range_max)
static const AVClass cudachromakey_class
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
static int format_is_supported(enum AVPixelFormat fmt)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
@ 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...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static const AVFilterPad cudachromakey_outputs[]
static int cudachromakey_filter_frame(AVFilterLink *link, AVFrame *in)
static const AVFilterPad cudachromakey_inputs[]
A reference to a data buffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static int cudachromakey_process_internal(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static int cudachromakey_process(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
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.