FFmpeg
Loading...
Searching...
No Matches
vf_overlay_cuda.c File Reference

Overlay one video on top of another using cuda hardware acceleration. More...

#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/cuda_check.h"
#include "libavutil/eval.h"
#include "avfilter.h"
#include "filters.h"
#include "framesync.h"
#include "cuda/load_helper.h"

Go to the source code of this file.

Data Structures

struct  OverlayCUDAContext
 OverlayCUDAContext. More...
 

Macros

#define CHECK_CU(x)
 
#define DIV_UP(a, b)
 
#define BLOCK_X   32
 
#define BLOCK_Y   16
 
#define MAIN   0
 
#define OVERLAY   1
 
#define OFFSET(x)
 
#define FLAGS   (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
 

Enumerations

enum  var_name {
  VAR_MAIN_W , VAR_MW , VAR_MAIN_H , VAR_MH ,
  VAR_OVERLAY_W , VAR_OW , VAR_OVERLAY_H , VAR_OH ,
  VAR_X , VAR_Y , VAR_N , VAR_T ,
  VAR_VARS_NB
}
 
enum  EvalMode { EVAL_MODE_INIT , EVAL_MODE_FRAME , EVAL_MODE_NB }
 

Functions

static int format_is_supported (const enum AVPixelFormat formats[], enum AVPixelFormat fmt)
 Helper to find out if provided format is supported by filter.
 
static int normalize_xy (double d, int chroma_sub)
 
static void eval_expr (AVFilterContext *ctx)
 
static int set_expr (AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
 
static int formats_match (const enum AVPixelFormat format_main, const enum AVPixelFormat format_overlay)
 Helper checks if we can process main and overlay pixel formats.
 
static int overlay_cuda_call_kernel (OverlayCUDAContext *ctx, int x_position, int y_position, uint8_t *main_data, int main_linesize, int main_width, int main_height, uint8_t *overlay_data, int overlay_linesize, int overlay_width, int overlay_height, uint8_t *alpha_data, int alpha_linesize, int alpha_adj_x, int alpha_adj_y)
 Call overlay kernell for a plane.
 
static int overlay_cuda_blend (FFFrameSync *fs)
 Perform blend overlay picture over main picture.
 
static int config_input_overlay (AVFilterLink *inlink)
 
static av_cold int overlay_cuda_init (AVFilterContext *avctx)
 Initialize overlay_cuda.
 
static av_cold void overlay_cuda_uninit (AVFilterContext *avctx)
 Uninitialize overlay_cuda.
 
static int overlay_cuda_activate (AVFilterContext *avctx)
 Activate overlay_cuda.
 
static int overlay_cuda_config_output (AVFilterLink *outlink)
 Configure output.
 
 FRAMESYNC_DEFINE_CLASS (overlay_cuda, OverlayCUDAContext, fs)
 

Variables

static enum AVPixelFormat supported_main_formats []
 
static enum AVPixelFormat supported_overlay_formats []
 
static const char *const var_names []
 
static const AVOption overlay_cuda_options []
 
static const AVFilterPad overlay_cuda_inputs []
 
static const AVFilterPad overlay_cuda_outputs []
 
const FFFilter ff_vf_overlay_cuda
 

Detailed Description

Overlay one video on top of another using cuda hardware acceleration.

Definition in file vf_overlay_cuda.c.

Macro Definition Documentation

◆ CHECK_CU

#define CHECK_CU ( x)
Value:
FF_CUDA_CHECK_DL(ctx, ctx->hwctx->internal->cuda_dl, x)
static AVFormatContext * ctx
#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 40 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_blend(), overlay_cuda_call_kernel(), overlay_cuda_config_output(), and overlay_cuda_uninit().

◆ DIV_UP

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

Definition at line 41 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_call_kernel().

◆ BLOCK_X

#define BLOCK_X   32

Definition at line 43 of file vf_overlay_cuda.c.

◆ BLOCK_Y

#define BLOCK_Y   16

Definition at line 44 of file vf_overlay_cuda.c.

◆ MAIN

#define MAIN   0

Definition at line 46 of file vf_overlay_cuda.c.

◆ OVERLAY

#define OVERLAY   1

Definition at line 47 of file vf_overlay_cuda.c.

◆ OFFSET

#define OFFSET ( x)
Value:
offsetof(OverlayCUDAContext, x)
OverlayCUDAContext.

Definition at line 522 of file vf_overlay_cuda.c.

◆ FLAGS

Definition at line 523 of file vf_overlay_cuda.c.

Enumeration Type Documentation

◆ var_name

enum var_name
Enumerator
VAR_MAIN_W 
VAR_MW 
VAR_MAIN_H 
VAR_MH 
VAR_OVERLAY_W 
VAR_OW 
VAR_OVERLAY_H 
VAR_OH 
VAR_X 
VAR_Y 
VAR_N 
VAR_T 
VAR_VARS_NB 

Definition at line 62 of file vf_overlay_cuda.c.

◆ EvalMode

enum EvalMode
Enumerator
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 

Definition at line 74 of file vf_overlay_cuda.c.

Function Documentation

◆ format_is_supported()

static int format_is_supported ( const enum AVPixelFormat formats[],
enum AVPixelFormat fmt )
static

Helper to find out if provided format is supported by filter.

Definition at line 124 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_config_output().

◆ normalize_xy()

static int normalize_xy ( double d,
int chroma_sub )
inlinestatic

Definition at line 132 of file vf_overlay_cuda.c.

Referenced by eval_expr().

◆ eval_expr()

static void eval_expr ( AVFilterContext * ctx)
static

Definition at line 139 of file vf_overlay_cuda.c.

Referenced by config_input_overlay(), and overlay_cuda_blend().

◆ set_expr()

static int set_expr ( AVExpr ** pexpr,
const char * expr,
const char * option,
void * log_ctx )
static

Definition at line 154 of file vf_overlay_cuda.c.

Referenced by config_input_overlay().

◆ formats_match()

static int formats_match ( const enum AVPixelFormat format_main,
const enum AVPixelFormat format_overlay )
static

Helper checks if we can process main and overlay pixel formats.

Definition at line 178 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_config_output().

◆ overlay_cuda_call_kernel()

static int overlay_cuda_call_kernel ( OverlayCUDAContext * ctx,
int x_position,
int y_position,
uint8_t * main_data,
int main_linesize,
int main_width,
int main_height,
uint8_t * overlay_data,
int overlay_linesize,
int overlay_width,
int overlay_height,
uint8_t * alpha_data,
int alpha_linesize,
int alpha_adj_x,
int alpha_adj_y )
static

Call overlay kernell for a plane.

Definition at line 193 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_blend().

◆ overlay_cuda_blend()

static int overlay_cuda_blend ( FFFrameSync * fs)
static

Perform blend overlay picture over main picture.

Definition at line 224 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_init().

◆ config_input_overlay()

static int config_input_overlay ( AVFilterLink * inlink)
static

Definition at line 336 of file vf_overlay_cuda.c.

◆ overlay_cuda_init()

static av_cold int overlay_cuda_init ( AVFilterContext * avctx)
static

Initialize overlay_cuda.

Definition at line 371 of file vf_overlay_cuda.c.

◆ overlay_cuda_uninit()

static av_cold void overlay_cuda_uninit ( AVFilterContext * avctx)
static

Uninitialize overlay_cuda.

Definition at line 382 of file vf_overlay_cuda.c.

◆ overlay_cuda_activate()

static int overlay_cuda_activate ( AVFilterContext * avctx)
static

Activate overlay_cuda.

Definition at line 405 of file vf_overlay_cuda.c.

◆ overlay_cuda_config_output()

static int overlay_cuda_config_output ( AVFilterLink * outlink)
static

Configure output.

Definition at line 415 of file vf_overlay_cuda.c.

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( overlay_cuda ,
OverlayCUDAContext ,
fs  )

Variable Documentation

◆ supported_main_formats

enum AVPixelFormat supported_main_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_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73

Definition at line 49 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_config_output().

◆ supported_overlay_formats

enum AVPixelFormat supported_overlay_formats[]
static
Initial value:
= {
}
@ 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 55 of file vf_overlay_cuda.c.

Referenced by overlay_cuda_config_output().

◆ var_names

const char* const var_names[]
static
Initial value:
= {
"main_w", "W",
"main_h", "H",
"overlay_w", "w",
"overlay_h", "h",
"x",
"y",
"n",
"t",
}
#define NULL
Definition coverity.c:32

Definition at line 80 of file vf_overlay_cuda.c.

◆ overlay_cuda_options

const AVOption overlay_cuda_options[]
static
Initial value:
= {
{ "x", "set the x expression of overlay", OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str = "0" }, 0, 0, FLAGS },
{ "y", "set the y expression of overlay", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "0" }, 0, 0, FLAGS },
{ "eof_action", "Action to take when encountering EOF from secondary input ",
OFFSET(fs.opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT },
EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, .unit = "eof_action" },
{ "repeat", "Repeat the previous frame.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, .unit = "eof_action" },
{ "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, .unit = "eof_action" },
{ "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, .unit = "eof_action" },
{ "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, { .i64 = EVAL_MODE_FRAME }, 0, EVAL_MODE_NB - 1, FLAGS, .unit = "eval" },
{ "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, { .i64=EVAL_MODE_INIT }, .flags = FLAGS, .unit = "eval" },
{ "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, { .i64=EVAL_MODE_FRAME }, .flags = FLAGS, .unit = "eval" },
{ "shortest", "force termination when the shortest input terminates", OFFSET(fs.opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "repeatlast", "repeat overlay of the last overlay frame", OFFSET(fs.opt_repeatlast), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
{ NULL },
}
@ EVAL_MODE_NB
Definition af_volume.h:42
@ EVAL_MODE_FRAME
Definition af_volume.h:41
#define fs(width, name, subs,...)
Definition cbs_vp9.c:200
#define FLAGS
Definition cmdutils.c:598
#define OFFSET(x)
@ EOF_ACTION_REPEAT
Definition framesync.h:27
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
@ EOF_ACTION_PASS
Definition packetsync.h:31
@ EOF_ACTION_ENDALL
Definition packetsync.h:30
@ EVAL_MODE_INIT
Definition vf_fftfilt.c:41

Definition at line 525 of file vf_overlay_cuda.c.

◆ overlay_cuda_inputs

const AVFilterPad overlay_cuda_inputs[]
static
Initial value:
= {
{
.name = "main",
},
{
.name = "overlay",
.config_props = config_input_overlay,
},
}
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int config_input_overlay(AVFilterLink *inlink)
Definition vf_overlay.c:291

Definition at line 544 of file vf_overlay_cuda.c.

◆ overlay_cuda_outputs

const AVFilterPad overlay_cuda_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = &overlay_cuda_config_output,
},
}
static int overlay_cuda_config_output(AVFilterLink *outlink)
Configure output.

Definition at line 556 of file vf_overlay_cuda.c.

◆ ff_vf_overlay_cuda

const FFFilter ff_vf_overlay_cuda
Initial value:
= {
.p.name = "overlay_cuda",
.p.description = NULL_IF_CONFIG_SMALL("Overlay one video on top of another using CUDA"),
.p.priv_class = &overlay_cuda_class,
.priv_size = sizeof(OverlayCUDAContext),
.preinit = overlay_cuda_framesync_preinit,
.flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
}
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition avfilter.h:204
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#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 overlay_cuda_inputs[]
static av_cold void overlay_cuda_uninit(AVFilterContext *avctx)
Uninitialize overlay_cuda.
static const AVFilterPad overlay_cuda_outputs[]
static int overlay_cuda_activate(AVFilterContext *avctx)
Activate overlay_cuda.
static av_cold int overlay_cuda_init(AVFilterContext *avctx)
Initialize overlay_cuda.

Definition at line 564 of file vf_overlay_cuda.c.