Skip to content

Commit be6cdf7

Browse files
ruiling-songlizhong1008
authored andcommitted
lavf/qsv: Support multiple inputs overlay composition
Based on patch by Liu, ChaoX. lavfi/vf_overlay_qsv: support mulit-inputs overlay. Description: 1. layout(grid/manual/overlay) default is the preset 'overlay' mode 2. x_expr,y_expr,w_expr,z_expr,a_expr If layout is set to overlay, these exprs will be used to calculate the [overlay] channel's output rect while the [main] channle will be forced the same as the 1st input. If layout is set to manual, these expressions will be used to construct the layout. Some const keys and funcs can be used. If keyword 'array' is used, the expressions must have enough comma-seprated statements to cover each input or it will cause an error. Otherwise, the single statement will be applied to each window. 3. Const values @array(\,) x_expr=array(expr1\,expr2\,...\,exprn) an array of expressions indicating each windows x/y/w/h @x(n),y(n),w(n),h(n),alpha(n),iw(n),ih(n) a group of functions that can get each windows position attributions, where n indicates the index counting from 0. @n,n Const values, N indicates the number of input windows while n indicates the index of current window. Examples: 1. ffmpeg -hwaccel qsv -c:v h264_qsv -i test.mp4 -filter_complex "split=4,overlay_qsv=4:manual:x_expr=w(n)*mod(n\,ceil(sqrt(N))):y_expr=h(n)*floor(n/ceil(sqrt(N))):w_expr=W/ceil(sqrt(N)):h_expr=H/ceil(sqrt(N))" -preset veryfast -c:v h264_qsv output.mp4 When calculating the layout, 'n' will be replaced by the index of current window and this is the way how 'grid' mode calculate. 2. ffmpeg -hwaccel qsv -c:v h264_qsv -i test.mp4 -filter_complex "split=4,overlay_qsv=4:manual:x_expr=array(0\,960\,0,960):y_expr=array(0\,0\,540\,540):w_expr=array(960,960,960,960):h_expr=array(540,540,540,540):a_expr=255" -preset veryfast -c:v h264_qsv output.mp4 This command is equal to the former one when test.mp4 is of FHD. 3. to overlay a video to area [(0,0), (256,256)] on another video, you can use: ffmpeg -hwaccel qsv -c:v h264_qsv -i test1.mp4 -hwaccel qsv -c:v h264_qsv -i test2.mp4 -filter_complex "overlay_qsv=x_expr=0:y_expr=0:w_expr=256:h_expr=256:a_expr=128" -preset veryfast -c:v h264_qsv output.mp4 Signed-off-by: Ruiling Song <ruiling.song@intel.com>
1 parent c194242 commit be6cdf7

2 files changed

Lines changed: 386 additions & 201 deletions

File tree

libavfilter/qsvvpp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131
#define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
3232
#define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
3333

34+
/* w or h = -n will be treated as factor n */
35+
#define eval_factor(ow, oh, link) do {\
36+
int factor_w = 1, factor_h = 1; \
37+
int iw = link->w, ih = link->h; \
38+
if (ow < -1) factor_w = -ow; \
39+
if (oh < -1) factor_h = -oh; \
40+
if (ow < 0 && oh < 0) ow = oh = 0; \
41+
if (!ow) ow = iw; \
42+
if (!oh) oh = ih; \
43+
if (ow < 0) ow = av_rescale(oh, iw, ih * factor_w) * factor_w; \
44+
if (oh < 0) oh = av_rescale(ow, ih, iw * factor_h) * factor_h; \
45+
} while (0);
46+
3447
typedef struct QSVVPPContext QSVVPPContext;
3548

3649
typedef struct QSVVPPCrop {

0 commit comments

Comments
 (0)