FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
framesync.h File Reference
#include "bufferqueue.h"

Go to the source code of this file.

Data Structures

struct  FFFrameSyncIn
 Input stream structure. More...
 
struct  FFFrameSync
 Frame sync structure. More...
 

Macros

#define FRAMESYNC_DEFINE_PURE_CLASS(name, desc, func_prefix, options)
 
#define FRAMESYNC_AUXILIARY_FUNCS(func_prefix, context, field)
 
#define FRAMESYNC_DEFINE_CLASS_EXT(name, context, field, options)
 
#define FRAMESYNC_DEFINE_CLASS(name, context, field)   FRAMESYNC_DEFINE_CLASS_EXT(name, context, field, name##_options)
 

Enumerations

enum  EOFAction {
  EOF_ACTION_REPEAT, EOF_ACTION_ENDALL, EOF_ACTION_PASS, EOF_ACTION_ROUND,
  EOF_ACTION_PASS, EOF_ACTION_NB
}
 
enum  FFFrameSyncExtMode { EXT_STOP, EXT_NULL, EXT_INFINITY }
 This API is intended as a helper for filters that have several video input and need to combine them somehow. More...
 
enum  FFFrameTSSyncMode { TS_DEFAULT, TS_NEAREST }
 Timestamp syncronization mode. More...
 

Functions

void ff_framesync_preinit (FFFrameSync *fs)
 Pre-initialize a frame sync structure. More...
 
int ff_framesync_init (FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
 Initialize a frame sync structure. More...
 
int ff_framesync_configure (FFFrameSync *fs)
 Configure a frame sync structure. More...
 
void ff_framesync_uninit (FFFrameSync *fs)
 Free all memory currently allocated. More...
 
int ff_framesync_get_frame (FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
 Get the current frame in an input. More...
 
int ff_framesync_activate (FFFrameSync *fs)
 Examine the frames in the filter's input and try to produce output. More...
 
int ff_framesync_init_dualinput (FFFrameSync *fs, AVFilterContext *parent)
 Initialize a frame sync structure for dualinput. More...
 
int ff_framesync_dualinput_get (FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
 
int ff_framesync_dualinput_get_writable (FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
 Same as ff_framesync_dualinput_get(), but make sure that f0 is writable. More...
 
const AVClassff_framesync_child_class_iterate (void **iter)
 

Variables

const AVClass ff_framesync_class
 

Macro Definition Documentation

◆ FRAMESYNC_DEFINE_PURE_CLASS

#define FRAMESYNC_DEFINE_PURE_CLASS (   name,
  desc,
  func_prefix,
  options 
)
Value:
static const AVClass name##_class = { \
.class_name = desc, \
.item_name = av_default_item_name, \
.option = options, \
.version = LIBAVUTIL_VERSION_INT, \
.category = AV_CLASS_CATEGORY_FILTER, \
.child_class_iterate = ff_framesync_child_class_iterate, \
.child_next = func_prefix##_child_next, \
}

Definition at line 321 of file framesync.h.

◆ FRAMESYNC_AUXILIARY_FUNCS

#define FRAMESYNC_AUXILIARY_FUNCS (   func_prefix,
  context,
  field 
)
Value:
static int func_prefix##_framesync_preinit(AVFilterContext *ctx) \
{ \
context *s = ctx->priv; \
ff_framesync_preinit(&s->field); \
return 0; \
} \
static void *func_prefix##_child_next(void *obj, void *prev) \
{ \
context *s = obj; \
return prev ? NULL : &s->field; \
}

Definition at line 335 of file framesync.h.

◆ FRAMESYNC_DEFINE_CLASS_EXT

#define FRAMESYNC_DEFINE_CLASS_EXT (   name,
  context,
  field,
  options 
)
Value:
FRAMESYNC_DEFINE_PURE_CLASS(name, #name, name, options)

Definition at line 348 of file framesync.h.

◆ FRAMESYNC_DEFINE_CLASS

#define FRAMESYNC_DEFINE_CLASS (   name,
  context,
  field 
)    FRAMESYNC_DEFINE_CLASS_EXT(name, context, field, name##_options)

Definition at line 352 of file framesync.h.

Enumeration Type Documentation

◆ EOFAction

enum EOFAction
Enumerator
EOF_ACTION_REPEAT 
EOF_ACTION_ENDALL 
EOF_ACTION_PASS 
EOF_ACTION_ROUND 
EOF_ACTION_PASS 
EOF_ACTION_NB 

Definition at line 26 of file framesync.h.

◆ FFFrameSyncExtMode

This API is intended as a helper for filters that have several video input and need to combine them somehow.

If the inputs have different or variable frame rate, getting the input frames to match requires a rather complex logic and a few user-tunable options.

In this API, when a set of synchronized input frames is ready to be procesed is called a frame event. Frame event can be generated in response to input frames on any or all inputs and the handling of situations where some stream extend beyond the beginning or the end of others can be configured.

The basic working of this API is the following: set the on_event callback, then call ff_framesync_activate() from the filter's activate callback. Stream extrapolation mode

Describe how the frames of a stream are extrapolated before the first one and after EOF to keep sync with possibly longer other streams.

Enumerator
EXT_STOP 

Completely stop all streams with this one.

EXT_NULL 

Ignore this stream and continue processing the other ones.

EXT_INFINITY 

Extend the frame to infinity.

Definition at line 60 of file framesync.h.

◆ FFFrameTSSyncMode

Timestamp syncronization mode.

Describe how the frames of a stream are syncronized based on timestamp distance.

Enumerator
TS_DEFAULT 

Sync to frames from secondary input with the nearest, lower or equal timestamp to the frame event one.

TS_NEAREST 

Sync to frames from secondary input with the absolute nearest timestamp to the frame event one.

Definition at line 84 of file framesync.h.

Function Documentation

◆ ff_framesync_preinit()

void ff_framesync_preinit ( FFFrameSync fs)

Pre-initialize a frame sync structure.

It sets the class pointer and inits the options to their default values. The entire structure is expected to be already set to 0. This step is optional, but necessary to use the options.

Definition at line 78 of file framesync.c.

Referenced by ff_framesync_init(), and preinit().

◆ ff_framesync_init()

int ff_framesync_init ( FFFrameSync fs,
AVFilterContext parent,
unsigned  nb_in 
)

Initialize a frame sync structure.

The entire structure is expected to be already set to 0 or preinited.

Parameters
fsframe sync structure to initialize
parentparent AVFilterContext object
nb_innumber of inputs
Returns
>= 0 for success or a negative error code

Definition at line 86 of file framesync.c.

Referenced by config_output(), config_props(), ff_framesync_init_dualinput(), init_framesync(), lut2_config_output(), and program_opencl_config_output().

◆ ff_framesync_configure()

int ff_framesync_configure ( FFFrameSync fs)

Configure a frame sync structure.

Must be called after all options are set but before all use.

Returns
>= 0 for success or a negative error code

Definition at line 137 of file framesync.c.

Referenced by config_output(), config_props(), config_props_output(), init_framesync(), lut2_config_output(), overlay_cuda_config_output(), overlay_opencl_config_output(), overlay_vaapi_config_output(), overlay_vulkan_config_output(), and program_opencl_config_output().

◆ ff_framesync_uninit()

void ff_framesync_uninit ( FFFrameSync fs)

◆ ff_framesync_get_frame()

int ff_framesync_get_frame ( FFFrameSync fs,
unsigned  in,
AVFrame **  rframe,
unsigned  get 
)

Get the current frame in an input.

Parameters
fsframe sync structure
inindex of the input
rframeused to return the current frame (or NULL)
getif not zero, the calling code needs to get ownership of the returned frame; the current frame will either be duplicated or removed from the framesync structure

Definition at line 269 of file framesync.c.

Referenced by blend_frame(), do_scale(), ff_framesync_dualinput_get(), overlay_opencl_blend(), overlay_vaapi_blend(), overlay_vulkan_blend(), process_frame(), program_opencl_filter(), and remap_opencl_process_frame().

◆ ff_framesync_activate()

int ff_framesync_activate ( FFFrameSync fs)

Examine the frames in the filter's input and try to produce output.

This function can be the complete implementation of the activate method of a filter using framesync.

Definition at line 352 of file framesync.c.

Referenced by activate(), overlay_cuda_activate(), overlay_opencl_activate(), overlay_vaapi_activate(), overlay_vulkan_activate(), program_opencl_activate(), and stack_activate().

◆ ff_framesync_init_dualinput()

int ff_framesync_init_dualinput ( FFFrameSync fs,
AVFilterContext parent 
)

Initialize a frame sync structure for dualinput.

Compared to generic framesync, dualinput assumes the first input is the main one and the filtering is performed on it. The first input will be the only one with sync set and generic timeline support will just pass it unchanged when disabled.

Equivalent to ff_framesync_init(fs, parent, 2) then setting the time base, sync and ext modes on the inputs.

Definition at line 372 of file framesync.c.

Referenced by config_output(), config_props_output(), overlay_cuda_config_output(), overlay_opencl_config_output(), overlay_vaapi_config_output(), and overlay_vulkan_config_output().

◆ ff_framesync_dualinput_get()

int ff_framesync_dualinput_get ( FFFrameSync fs,
AVFrame **  f0,
AVFrame **  f1 
)
Parameters
f0used to return the main frame
f1used to return the second frame, or NULL if disabled
Returns
>=0 for success or AVERROR code
Note
The frame returned in f0 belongs to the caller (get = 1 in ff_framesync_get_frame()) while the frame returned in f1 is still owned by the framesync structure.

Definition at line 390 of file framesync.c.

Referenced by blend_frame_for_dualinput(), do_convolve(), do_corr(), do_identity(), do_morpho(), do_psnr(), do_ssim(), do_ssim360(), do_vmaf(), do_xpsnr(), ff_framesync_dualinput_get_writable(), overlay_cuda_blend(), process_frame(), and varblur_frame().

◆ ff_framesync_dualinput_get_writable()

int ff_framesync_dualinput_get_writable ( FFFrameSync fs,
AVFrame **  f0,
AVFrame **  f1 
)

Same as ff_framesync_dualinput_get(), but make sure that f0 is writable.

Definition at line 410 of file framesync.c.

Referenced by do_alphamerge(), do_blend(), and load_apply_palette().

◆ ff_framesync_child_class_iterate()

const AVClass* ff_framesync_child_class_iterate ( void **  iter)

Definition at line 63 of file framesync.c.

Variable Documentation

◆ ff_framesync_class

const AVClass ff_framesync_class
name
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 name
Definition: writing_filters.txt:88
FRAMESYNC_AUXILIARY_FUNCS
#define FRAMESYNC_AUXILIARY_FUNCS(func_prefix, context, field)
Definition: framesync.h:335
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:49
field
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 field
Definition: writing_filters.txt:78
context
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
Definition: writing_filters.txt:91
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
options
Definition: swscale.c:42
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
options
const OptionDef options[]
AVClass::child_next
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:149
ff_framesync_child_class_iterate
const AVClass * ff_framesync_child_class_iterate(void **iter)
Definition: framesync.c:63
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
desc
const char * desc
Definition: libsvtav1.c:79