19#define OFFSET(x) offsetof(StackHWContext, x)
20#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
22#define SET_OUTPUT_REGION(region, rx, ry, rw, rh) do { \
26 region->height = rh; \
31 StackBaseContext *sctx = avctx->
priv;
39 sctx->fs.opaque = sctx;
41 for (
int i = 0;
i < sctx->nb_inputs;
i++) {
57 StackBaseContext *sctx = avctx->
priv;
62 if (sctx->mode == STACK_H) {
63 height = sctx->tile_height;
69 for (
int i = 0;
i < sctx->nb_inputs;
i++) {
71 StackItemRegion *region = &sctx->regions[
i];
76 }
else if (sctx->mode == STACK_V) {
78 width = sctx->tile_width;
83 for (
int i = 0;
i < sctx->nb_inputs;
i++) {
85 StackItemRegion *region = &sctx->regions[
i];
90 }
else if (sctx->nb_grid_rows && sctx->nb_grid_columns) {
91 int xpos = 0, ypos = 0;
94 ow = sctx->tile_width;
95 oh = sctx->tile_height;
102 for (
int i = 0;
i < sctx->nb_grid_columns;
i++) {
105 for (
int j = 0; j < sctx->nb_grid_rows; j++) {
106 StackItemRegion *region = &sctx->regions[k++];
115 width = ow * sctx->nb_grid_columns;
116 height = oh * sctx->nb_grid_rows;
118 char *
arg, *p = sctx->layout, *saveptr =
NULL;
119 char *arg2, *p2, *saveptr2 =
NULL;
120 char *arg3, *p3, *saveptr3 =
NULL;
121 int xpos, ypos,
size;
127 for (
int i = 0;
i < sctx->nb_inputs;
i++) {
129 StackItemRegion *region = &sctx->regions[
i];
141 for (
int j = 0; j < 3; j++) {
142 if (!(arg2 =
av_strtok(p2,
"_", &saveptr2))) {
161 while ((arg3 =
av_strtok(p3,
"+", &saveptr3))) {
163 if (sscanf(arg3,
"w%d", &
size) == 1) {
168 xpos += sctx->regions[
size].width;
170 ypos += sctx->regions[
size].width;
171 }
else if (sscanf(arg3,
"h%d", &
size) == 1) {
176 xpos += sctx->regions[
size].height;
178 ypos += sctx->regions[
size].height;
179 }
else if (sscanf(arg3,
"%d", &
size) == 1) {
205 for (
int i = 1;
i < sctx->nb_inputs;
i++) {
210 "Video inputs have different frame rates, output will be VFR\n");
227 StackBaseContext *sctx = avctx->
priv;
231 sctx->mode = STACK_H;
233 sctx->mode = STACK_V;
238 sctx->mode = STACK_X;
239 is_grid = sctx->nb_grid_rows && sctx->nb_grid_columns;
241 if (sctx->layout && is_grid) {
242 av_log(avctx,
AV_LOG_ERROR,
"Both layout and grid were specified. Only one is allowed.\n");
246 if (!sctx->layout && !is_grid) {
247 if (sctx->nb_inputs == 2) {
248 sctx->nb_grid_rows = 1;
249 sctx->nb_grid_columns = 2;
258 sctx->nb_inputs = sctx->nb_grid_rows * sctx->nb_grid_columns;
260 if (strcmp(sctx->fillcolor_str,
"none") &&
261 av_parse_color(sctx->fillcolor, sctx->fillcolor_str, -1, avctx) >= 0) {
262 sctx->fillcolor_enable = 1;
264 sctx->fillcolor_enable = 0;
268 for (
int i = 0;
i < sctx->nb_inputs;
i++) {
281 sctx->regions =
av_calloc(sctx->nb_inputs,
sizeof(*sctx->regions));
290 StackBaseContext *sctx = avctx->
priv;
298 StackBaseContext *sctx = avctx->
priv;
310#define STACK_COMMON_OPTS \
311 { "inputs", "Set number of inputs", OFFSET(base.nb_inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 2, UINT16_MAX, .flags = FLAGS }, \
312 { "shortest", "Force termination when the shortest input terminates", OFFSET(base.shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
314#define DEFINE_HSTACK_OPTIONS(api) \
315 static const AVOption hstack_##api##_options[] = { \
317 { "height", "Set output height (0 to use the height of input 0)", OFFSET(base.tile_height), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, FLAGS }, \
321#define DEFINE_VSTACK_OPTIONS(api) \
322 static const AVOption vstack_##api##_options[] = { \
324 { "width", "Set output width (0 to use the width of input 0)", OFFSET(base.tile_width), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, FLAGS }, \
328#define DEFINE_XSTACK_OPTIONS(api) \
329 static const AVOption xstack_##api##_options[] = { \
331 { "layout", "Set custom layout", OFFSET(base.layout), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, .flags = FLAGS }, \
332 { "grid", "set fixed size grid layout", OFFSET(base.nb_grid_columns), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, .flags = FLAGS }, \
333 { "grid_tile_size", "set tile size in grid layout", OFFSET(base.tile_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, .flags = FLAGS }, \
334 { "fill", "Set the color for unused pixels", OFFSET(base.fillcolor_str), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = FLAGS }, \
338#define DEFINE_STACK_FILTER(category, api, capi, filter_flags) \
339 static const AVClass category##_##api##_class = { \
340 .class_name = #category "_" #api, \
341 .item_name = av_default_item_name, \
342 .option = category##_##api##_options, \
343 .version = LIBAVUTIL_VERSION_INT, \
345 const FFFilter ff_vf_##category##_##api = { \
346 .p.name = #category "_" #api, \
347 .p.description = NULL_IF_CONFIG_SMALL(#capi " " #category), \
348 .p.flags = AVFILTER_FLAG_DYNAMIC_INPUTS | filter_flags, \
349 .p.priv_class = &category##_##api##_class, \
350 .priv_size = sizeof(StackHWContext), \
351 .init = api##_stack_init, \
352 .uninit = api##_stack_uninit, \
353 .activate = stack_activate, \
354 FILTER_PIXFMTS_ARRAY(api ## _stack_pix_fmts), \
355 FILTER_OUTPUTS(stack_outputs), \
356 .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, \
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
char * av_asprintf(const char *fmt,...)
#define i(width, name, range_min, range_max)
static av_always_inline int process_frame(AVTextFormatContext *tfc, InputFile *ifile, AVFrame *frame, const AVPacket *pkt, int *packet_new)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
@ EXT_INFINITY
Extend the frame to infinity.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
static int config_output(AVBitStreamFilterLink *outlink)
static FilterLink * ff_filter_link(AVFilterLink *link)
void * av_calloc(size_t nmemb, size_t size)
@ EXT_STOP
Completely stop all streams with this one.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
static int stack_activate(AVFilterContext *avctx)
static int stack_init(AVFilterContext *avctx)
static int init_framesync(AVFilterContext *avctx)
static int config_comm_output(AVFilterLink *outlink)
#define SET_OUTPUT_REGION(region, rx, ry, rw, rh)
static av_cold void stack_uninit(AVFilterContext *avctx)
static const AVFilterPad stack_outputs[]
unsigned nb_inputs
number of input pads
AVFilterLink ** inputs
array of pointers to input links
const AVFilter * filter
the AVFilter of which this is an instance
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
A filter pad used for either input or output.
enum AVMediaType type
AVFilterPad type.
const char * name
Pad name.
const char * name
Filter name.
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
AVRational time_base
Time base for the incoming frames.
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.