FFmpeg
Loading...
Searching...
No Matches
vf_overlay_cuda.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Yaroslav Pogrebnyak <yyyaroslav@gmail.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/**
22 * @file
23 * Overlay one video on top of another using cuda hardware acceleration
24 */
25
26#include "libavutil/log.h"
27#include "libavutil/opt.h"
28#include "libavutil/pixdesc.h"
29#include "libavutil/hwcontext.h"
32#include "libavutil/eval.h"
33
34#include "avfilter.h"
35#include "filters.h"
36#include "framesync.h"
37
38#include "cuda/load_helper.h"
39
40#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, ctx->hwctx->internal->cuda_dl, x)
41#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
42
43#define BLOCK_X 32
44#define BLOCK_Y 16
45
46#define MAIN 0
47#define OVERLAY 1
48
54
61
73
79
80static const char *const var_names[] = {
81 "main_w", "W", ///< width of the main video
82 "main_h", "H", ///< height of the main video
83 "overlay_w", "w", ///< width of the overlay video
84 "overlay_h", "h", ///< height of the overlay video
85 "x",
86 "y",
87 "n", ///< number of frame
88 "t", ///< timestamp expressed in seconds
89 NULL
90};
91
92/**
93 * OverlayCUDAContext
94 */
120
121/**
122 * Helper to find out if provided format is supported by filter
123 */
124static int format_is_supported(const enum AVPixelFormat formats[], enum AVPixelFormat fmt)
125{
126 for (int i = 0; formats[i] != AV_PIX_FMT_NONE; i++)
127 if (formats[i] == fmt)
128 return 1;
129 return 0;
130}
131
132static inline int normalize_xy(double d, int chroma_sub)
133{
134 if (isnan(d))
135 return INT_MAX;
136 return (int)d & ~((1 << chroma_sub) - 1);
137}
138
140{
141 OverlayCUDAContext *s = ctx->priv;
142
143 s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
144 s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, NULL);
145 /* necessary if x is expressed from y */
146 s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, NULL);
147
148 s->x_position = normalize_xy(s->var_values[VAR_X], 1);
149
150 /* the cuda pixel format is using hwaccel, normalizing y is unnecessary */
151 s->y_position = s->var_values[VAR_Y];
152}
153
154static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
155{
156 int ret;
157 AVExpr *old = NULL;
158
159 if (*pexpr)
160 old = *pexpr;
161 ret = av_expr_parse(pexpr, expr, var_names,
162 NULL, NULL, NULL, NULL, 0, log_ctx);
163 if (ret < 0) {
164 av_log(log_ctx, AV_LOG_ERROR,
165 "Error when evaluating the expression '%s' for %s\n",
166 expr, option);
167 *pexpr = old;
168 return ret;
169 }
170
171 av_expr_free(old);
172 return 0;
173}
174
175/**
176 * Helper checks if we can process main and overlay pixel formats
177 */
178static int formats_match(const enum AVPixelFormat format_main, const enum AVPixelFormat format_overlay) {
179 switch(format_main) {
180 case AV_PIX_FMT_NV12:
181 return format_overlay == AV_PIX_FMT_NV12;
183 return format_overlay == AV_PIX_FMT_YUV420P ||
184 format_overlay == AV_PIX_FMT_YUVA420P;
185 default:
186 return 0;
187 }
188}
189
190/**
191 * Call overlay kernell for a plane
192 */
195 int x_position, int y_position,
196 uint8_t* main_data, int main_linesize,
197 int main_width, int main_height,
198 uint8_t* overlay_data, int overlay_linesize,
199 int overlay_width, int overlay_height,
200 uint8_t* alpha_data, int alpha_linesize,
201 int alpha_adj_x, int alpha_adj_y) {
202
203 CudaFunctions *cu = ctx->hwctx->internal->cuda_dl;
204
205 void* kernel_args[] = {
206 &x_position, &y_position,
207 &main_data, &main_linesize,
208 &overlay_data, &overlay_linesize,
209 &overlay_width, &overlay_height,
210 &alpha_data, &alpha_linesize,
211 &alpha_adj_x, &alpha_adj_y,
212 };
213
214 return CHECK_CU(cu->cuLaunchKernel(
215 ctx->cu_func,
216 DIV_UP(main_width, BLOCK_X), DIV_UP(main_height, BLOCK_Y), 1,
217 BLOCK_X, BLOCK_Y, 1,
218 0, ctx->cu_stream, kernel_args, NULL));
219}
220
221/**
222 * Perform blend overlay picture over main picture
223 */
225{
226 int ret;
227
228 AVFilterContext *avctx = fs->parent;
229 OverlayCUDAContext *ctx = avctx->priv;
230 AVFilterLink *outlink = avctx->outputs[0];
231 AVFilterLink *inlink = avctx->inputs[0];
232 FilterLink *inl = ff_filter_link(inlink);
233
234 CudaFunctions *cu = ctx->hwctx->internal->cuda_dl;
235 CUcontext dummy, cuda_ctx = ctx->hwctx->cuda_ctx;
236
237 AVFrame *input_main, *input_overlay;
238
239 ctx->cu_ctx = cuda_ctx;
240
241 // read main and overlay frames from inputs
242 ret = ff_framesync_dualinput_get(fs, &input_main, &input_overlay);
243 if (ret < 0)
244 return ret;
245
246 if (!input_main)
247 return AVERROR_BUG;
248
249 if (!input_overlay)
250 return ff_filter_frame(outlink, input_main);
251
252 ret = ff_inlink_make_frame_writable(inlink, &input_main);
253 if (ret < 0) {
254 av_frame_free(&input_main);
255 return ret;
256 }
257
258 // push cuda context
259
260 ret = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
261 if (ret < 0) {
262 av_frame_free(&input_main);
263 return ret;
264 }
265
266 if (ctx->eval_mode == EVAL_MODE_FRAME) {
267 ctx->var_values[VAR_N] = inl->frame_count_out;
268 ctx->var_values[VAR_T] = input_main->pts == AV_NOPTS_VALUE ?
269 NAN : input_main->pts * av_q2d(inlink->time_base);
270
271 ctx->var_values[VAR_OVERLAY_W] = ctx->var_values[VAR_OW] = input_overlay->width;
272 ctx->var_values[VAR_OVERLAY_H] = ctx->var_values[VAR_OH] = input_overlay->height;
273 ctx->var_values[VAR_MAIN_W ] = ctx->var_values[VAR_MW] = input_main->width;
274 ctx->var_values[VAR_MAIN_H ] = ctx->var_values[VAR_MH] = input_main->height;
275
276 eval_expr(avctx);
277
278 av_log(avctx, AV_LOG_DEBUG, "n:%f t:%f x:%f xi:%d y:%f yi:%d\n",
279 ctx->var_values[VAR_N], ctx->var_values[VAR_T],
280 ctx->var_values[VAR_X], ctx->x_position,
281 ctx->var_values[VAR_Y], ctx->y_position);
282 }
283
284 // overlay first plane
285
287 ctx->x_position, ctx->y_position,
288 input_main->data[0], input_main->linesize[0],
289 input_main->width, input_main->height,
290 input_overlay->data[0], input_overlay->linesize[0],
291 input_overlay->width, input_overlay->height,
292 input_overlay->data[3], input_overlay->linesize[3], 1, 1);
293
294 // overlay rest planes depending on pixel format
295
296 switch(ctx->in_format_overlay) {
297 case AV_PIX_FMT_NV12:
299 ctx->x_position, ctx->y_position / 2,
300 input_main->data[1], input_main->linesize[1],
301 input_main->width, input_main->height / 2,
302 input_overlay->data[1], input_overlay->linesize[1],
303 input_overlay->width, input_overlay->height / 2,
304 0, 0, 0, 0);
305 break;
309 ctx->x_position / 2 , ctx->y_position / 2,
310 input_main->data[1], input_main->linesize[1],
311 input_main->width / 2, input_main->height / 2,
312 input_overlay->data[1], input_overlay->linesize[1],
313 input_overlay->width / 2, input_overlay->height / 2,
314 input_overlay->data[3], input_overlay->linesize[3], 2, 2);
315
317 ctx->x_position / 2 , ctx->y_position / 2,
318 input_main->data[2], input_main->linesize[2],
319 input_main->width / 2, input_main->height / 2,
320 input_overlay->data[2], input_overlay->linesize[2],
321 input_overlay->width / 2, input_overlay->height / 2,
322 input_overlay->data[3], input_overlay->linesize[3], 2, 2);
323 break;
324 default:
325 av_log(ctx, AV_LOG_ERROR, "Passed unsupported overlay pixel format\n");
326 av_frame_free(&input_main);
327 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
328 return AVERROR_BUG;
329 }
330
331 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
332
333 return ff_filter_frame(outlink, input_main);
334}
335
337{
338 AVFilterContext *ctx = inlink->dst;
339 OverlayCUDAContext *s = inlink->dst->priv;
340 int ret;
341
342
343 /* Finish the configuration by evaluating the expressions
344 now when both inputs are configured. */
345 s->var_values[VAR_MAIN_W ] = s->var_values[VAR_MW] = ctx->inputs[MAIN ]->w;
346 s->var_values[VAR_MAIN_H ] = s->var_values[VAR_MH] = ctx->inputs[MAIN ]->h;
347 s->var_values[VAR_OVERLAY_W] = s->var_values[VAR_OW] = ctx->inputs[OVERLAY]->w;
348 s->var_values[VAR_OVERLAY_H] = s->var_values[VAR_OH] = ctx->inputs[OVERLAY]->h;
349 s->var_values[VAR_X] = NAN;
350 s->var_values[VAR_Y] = NAN;
351 s->var_values[VAR_N] = 0;
352 s->var_values[VAR_T] = NAN;
353
354 if ((ret = set_expr(&s->x_pexpr, s->x_expr, "x", ctx)) < 0 ||
355 (ret = set_expr(&s->y_pexpr, s->y_expr, "y", ctx)) < 0)
356 return ret;
357
358 if (s->eval_mode == EVAL_MODE_INIT) {
359 eval_expr(ctx);
360 av_log(ctx, AV_LOG_VERBOSE, "x:%f xi:%d y:%f yi:%d\n",
361 s->var_values[VAR_X], s->x_position,
362 s->var_values[VAR_Y], s->y_position);
363 }
364
365 return 0;
366}
367
368/**
369 * Initialize overlay_cuda
370 */
372{
373 OverlayCUDAContext* ctx = avctx->priv;
374 ctx->fs.on_event = &overlay_cuda_blend;
375
376 return 0;
377}
378
379/**
380 * Uninitialize overlay_cuda
381 */
383{
384 OverlayCUDAContext* ctx = avctx->priv;
385
387
388 if (ctx->hwctx && ctx->cu_module) {
389 CUcontext dummy;
390 CudaFunctions *cu = ctx->hwctx->internal->cuda_dl;
391 CHECK_CU(cu->cuCtxPushCurrent(ctx->cu_ctx));
392 CHECK_CU(cu->cuModuleUnload(ctx->cu_module));
393 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
394 }
395
396 av_expr_free(ctx->x_pexpr); ctx->x_pexpr = NULL;
397 av_expr_free(ctx->y_pexpr); ctx->y_pexpr = NULL;
398 av_buffer_unref(&ctx->hw_device_ctx);
399 ctx->hwctx = NULL;
400}
401
402/**
403 * Activate overlay_cuda
404 */
406{
407 OverlayCUDAContext *ctx = avctx->priv;
408
409 return ff_framesync_activate(&ctx->fs);
410}
411
412/**
413 * Configure output
414 */
416{
417 extern const unsigned char ff_vf_overlay_cuda_ptx_data[];
418 extern const unsigned int ff_vf_overlay_cuda_ptx_len;
419
420 int err;
421 FilterLink *outl = ff_filter_link(outlink);
422 AVFilterContext* avctx = outlink->src;
423 OverlayCUDAContext* ctx = avctx->priv;
424
425 AVFilterLink *inlink = avctx->inputs[0];
426 FilterLink *inl = ff_filter_link(inlink);
428
429 AVFilterLink *inlink_overlay = avctx->inputs[1];
430 FilterLink *inl_overlay = ff_filter_link(inlink_overlay);
431 AVHWFramesContext *frames_ctx_overlay = (AVHWFramesContext*)inl_overlay->hw_frames_ctx->data;
432
433 CUcontext dummy, cuda_ctx;
434 CudaFunctions *cu;
435
436 // check main input formats
437
438 if (!frames_ctx) {
439 av_log(ctx, AV_LOG_ERROR, "No hw context provided on main input\n");
440 return AVERROR(EINVAL);
441 }
442
443 ctx->in_format_main = frames_ctx->sw_format;
444 if (!format_is_supported(supported_main_formats, ctx->in_format_main)) {
445 av_log(ctx, AV_LOG_ERROR, "Unsupported main input format: %s\n",
446 av_get_pix_fmt_name(ctx->in_format_main));
447 return AVERROR(ENOSYS);
448 }
449
450 // check overlay input formats
451
452 if (!frames_ctx_overlay) {
453 av_log(ctx, AV_LOG_ERROR, "No hw context provided on overlay input\n");
454 return AVERROR(EINVAL);
455 }
456
457 ctx->in_format_overlay = frames_ctx_overlay->sw_format;
458 if (!format_is_supported(supported_overlay_formats, ctx->in_format_overlay)) {
459 av_log(ctx, AV_LOG_ERROR, "Unsupported overlay input format: %s\n",
460 av_get_pix_fmt_name(ctx->in_format_overlay));
461 return AVERROR(ENOSYS);
462 }
463
464 // check we can overlay pictures with those pixel formats
465
466 if (!formats_match(ctx->in_format_main, ctx->in_format_overlay)) {
467 av_log(ctx, AV_LOG_ERROR, "Can't overlay %s on %s \n",
468 av_get_pix_fmt_name(ctx->in_format_overlay), av_get_pix_fmt_name(ctx->in_format_main));
469 return AVERROR(EINVAL);
470 }
471
472 // initialize
473
474 ctx->hw_device_ctx = av_buffer_ref(frames_ctx->device_ref);
475 if (!ctx->hw_device_ctx)
476 return AVERROR(ENOMEM);
477 ctx->hwctx = ((AVHWDeviceContext*)ctx->hw_device_ctx->data)->hwctx;
478
479 cuda_ctx = ctx->hwctx->cuda_ctx;
480 ctx->fs.time_base = inlink->time_base;
481
482 ctx->cu_stream = ctx->hwctx->stream;
483
485 if (!outl->hw_frames_ctx)
486 return AVERROR(ENOMEM);
487
488 // load functions
489
490 cu = ctx->hwctx->internal->cuda_dl;
491
492 err = CHECK_CU(cu->cuCtxPushCurrent(cuda_ctx));
493 if (err < 0) {
494 return err;
495 }
496
497 err = ff_cuda_load_module(ctx, ctx->hwctx, &ctx->cu_module, ff_vf_overlay_cuda_ptx_data, ff_vf_overlay_cuda_ptx_len);
498 if (err < 0) {
499 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
500 return err;
501 }
502
503 err = CHECK_CU(cu->cuModuleGetFunction(&ctx->cu_func, ctx->cu_module, "Overlay_Cuda"));
504 if (err < 0) {
505 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
506 return err;
507 }
508
509 CHECK_CU(cu->cuCtxPopCurrent(&dummy));
510
511 // init dual input
512
513 err = ff_framesync_init_dualinput(&ctx->fs, avctx);
514 if (err < 0) {
515 return err;
516 }
517
518 return ff_framesync_configure(&ctx->fs);
519}
520
521
522#define OFFSET(x) offsetof(OverlayCUDAContext, x)
523#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
524
526 { "x", "set the x expression of overlay", OFFSET(x_expr), AV_OPT_TYPE_STRING, { .str = "0" }, 0, 0, FLAGS },
527 { "y", "set the y expression of overlay", OFFSET(y_expr), AV_OPT_TYPE_STRING, { .str = "0" }, 0, 0, FLAGS },
528 { "eof_action", "Action to take when encountering EOF from secondary input ",
529 OFFSET(fs.opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT },
530 EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, .unit = "eof_action" },
531 { "repeat", "Repeat the previous frame.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, .unit = "eof_action" },
532 { "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, .unit = "eof_action" },
533 { "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, .unit = "eof_action" },
534 { "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" },
535 { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, { .i64=EVAL_MODE_INIT }, .flags = FLAGS, .unit = "eval" },
536 { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, { .i64=EVAL_MODE_FRAME }, .flags = FLAGS, .unit = "eval" },
537 { "shortest", "force termination when the shortest input terminates", OFFSET(fs.opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
538 { "repeatlast", "repeat overlay of the last overlay frame", OFFSET(fs.opt_repeatlast), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
539 { NULL },
540};
541
543
545 {
546 .name = "main",
547 .type = AVMEDIA_TYPE_VIDEO,
548 },
549 {
550 .name = "overlay",
551 .type = AVMEDIA_TYPE_VIDEO,
552 .config_props = config_input_overlay,
553 },
554};
555
557 {
558 .name = "default",
559 .type = AVMEDIA_TYPE_VIDEO,
560 .config_props = &overlay_cuda_config_output,
561 },
562};
563
565 .p.name = "overlay_cuda",
566 .p.description = NULL_IF_CONFIG_SMALL("Overlay one video on top of another using CUDA"),
567 .p.priv_class = &overlay_cuda_class,
568 .priv_size = sizeof(OverlayCUDAContext),
575 .preinit = overlay_cuda_framesync_preinit,
577 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
578};
@ VAR_T
Definition aeval.c:53
static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
Definition af_volume.c:92
EvalMode
Definition af_volume.h:39
@ EVAL_MODE_NB
Definition af_volume.h:42
@ EVAL_MODE_FRAME
Definition af_volume.h:41
const FFFilter ff_vf_overlay_cuda
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition avfilter.c:1567
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define fs(width, name, subs,...)
Definition cbs_vp9.c:200
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition eval.c:368
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition eval.c:824
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition eval.c:735
simple arithmetic expression evaluator
static int dummy
Definition ffplay.c:3754
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition framesync.c:137
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition framesync.c:390
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
Definition framesync.c:352
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
Definition framesync.c:372
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition framesync.c:301
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
Definition framesync.h:352
@ 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
#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
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
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:103
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
FFmpeg internal API for CUDA.
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
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition filters.h:254
@ VAR_X
Definition vf_blend.c:55
@ VAR_Y
Definition vf_blend.c:55
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
option
Definition libkvazaar.c:312
#define isnan(x)
Definition libm.h:342
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:34
#define NAN
var_name
Definition noise.c:46
@ VAR_N
Definition noise.c:47
@ VAR_VARS_NB
Definition noise.c:59
static const char *const var_names[]
Definition noise.c:30
AVOptions.
@ EOF_ACTION_PASS
Definition packetsync.h:31
@ EOF_ACTION_ENDALL
Definition packetsync.h:30
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:3380
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ 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
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
@ VAR_OH
Definition scale_eval.c:47
@ VAR_OW
Definition scale_eval.c:46
formats
Definition signature.h:47
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
Definition log.h:76
Definition eval.c:171
An instance of a filter.
Definition avfilter.h:273
AVFilterLink ** inputs
array of pointers to input links
Definition avfilter.h:281
void * priv
private data for use by the filter
Definition avfilter.h:288
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int width
Definition frame.h:544
int height
Definition frame.h:544
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:517
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition hwcontext.h:129
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
AVOption.
Definition opt.h:428
Frame sync structure.
Definition framesync.h:168
OverlayCUDAContext.
enum AVPixelFormat in_format_main
enum AVPixelFormat in_format_overlay
AVBufferRef * hw_device_ctx
double var_values[VAR_VARS_NB]
AVCUDADeviceContext * hwctx
#define av_log(a,...)
#define DIV_UP(a, b)
@ VAR_MAIN_H
@ VAR_MAIN_W
@ EVAL_MODE_INIT
Definition vf_fftfilt.c:41
static int config_input_overlay(AVFilterLink *inlink)
Definition vf_overlay.c:291
#define MAIN
Definition vf_overlay.c:62
#define OVERLAY
Definition vf_overlay.c:63
@ VAR_OVERLAY_H
Definition vf_overlay.h:31
@ VAR_MW
Definition vf_overlay.h:28
@ VAR_MH
Definition vf_overlay.h:29
@ VAR_OVERLAY_W
Definition vf_overlay.h:30
@ VAR_VARS_NB
static int overlay_cuda_config_output(AVFilterLink *outlink)
Configure output.
static enum AVPixelFormat supported_main_formats[]
static int config_input_overlay(AVFilterLink *inlink)
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 const AVOption overlay_cuda_options[]
static int format_is_supported(const enum AVPixelFormat formats[], enum AVPixelFormat fmt)
Helper to find out if provided format is supported by filter.
#define DIV_UP(a, b)
static const AVFilterPad overlay_cuda_inputs[]
static int overlay_cuda_blend(FFFrameSync *fs)
Perform blend overlay picture over main picture.
static enum AVPixelFormat supported_overlay_formats[]
static av_cold void overlay_cuda_uninit(AVFilterContext *avctx)
Uninitialize overlay_cuda.
static const AVFilterPad overlay_cuda_outputs[]
static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
static int overlay_cuda_activate(AVFilterContext *avctx)
Activate overlay_cuda.
static av_cold int overlay_cuda_init(AVFilterContext *avctx)
Initialize overlay_cuda.
#define CHECK_CU(x)
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.
#define OFFSET(x)
static void eval_expr(AVFilterContext *ctx)
static int normalize_xy(double d, int chroma_sub)
#define BLOCK_X
Definition vp3.c:640
#define BLOCK_Y
Definition vp3.c:641