FFmpeg
Macros | Functions | Variables
avfiltergraph.c File Reference
#include "config.h"
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "avfilter_internal.h"
#include "buffersink.h"
#include "filters.h"
#include "formats.h"
#include "framequeue.h"
#include "video.h"

Go to the source code of this file.

Macros

#define OFFSET(x)   offsetof(AVFilterGraph, x)
 
#define F   AV_OPT_FLAG_FILTERING_PARAM
 
#define V   AV_OPT_FLAG_VIDEO_PARAM
 
#define A   AV_OPT_FLAG_AUDIO_PARAM
 
#define MERGE(merger, link)
 
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format)
 
#define CH_CENTER_PAIR   (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
 
#define CH_FRONT_PAIR   (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
 
#define CH_STEREO_PAIR   (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
 
#define CH_WIDE_PAIR   (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
 
#define CH_SIDE_PAIR   (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
 
#define CH_DIRECT_PAIR   (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
 
#define CH_BACK_PAIR   (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
 

Functions

void ff_graph_thread_free (FFFilterGraph *graph)
 
int ff_graph_thread_init (FFFilterGraph *graph)
 
AVFilterGraphavfilter_graph_alloc (void)
 Allocate a filter graph. More...
 
void ff_filter_graph_remove_filter (AVFilterGraph *graph, AVFilterContext *filter)
 Remove a filter from a graph;. More...
 
void avfilter_graph_free (AVFilterGraph **graphp)
 Free a graph, destroy its links, and set *graph to NULL. More...
 
int avfilter_graph_create_filter (AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
 A convenience wrapper that allocates and initializes a filter in a single step. More...
 
void avfilter_graph_set_auto_convert (AVFilterGraph *graph, unsigned flags)
 Enable or disable automatic format conversion inside the graph. More...
 
AVFilterContextavfilter_graph_alloc_filter (AVFilterGraph *graph, const AVFilter *filter, const char *name)
 Create a new filter instance in a filter graph. More...
 
static int graph_check_validity (AVFilterGraph *graph, void *log_ctx)
 Check for the validity of graph. More...
 
static int graph_config_links (AVFilterGraph *graph, void *log_ctx)
 Configure all the links of graphctx. More...
 
static int graph_check_links (AVFilterGraph *graph, void *log_ctx)
 
AVFilterContextavfilter_graph_get_filter (AVFilterGraph *graph, const char *name)
 Get a filter instance identified by instance name from graph. More...
 
static int filter_link_check_formats (void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
 
static int filter_check_formats (AVFilterContext *ctx)
 Check the validity of the formats / etc. More...
 
static int filter_query_formats (AVFilterContext *ctx)
 
static int formats_declared (AVFilterContext *f)
 
static int query_formats (AVFilterGraph *graph, void *log_ctx)
 Perform one round of query_formats() and merging formats lists on the filter graph. More...
 
static int get_fmt_score (enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
 
static enum AVSampleFormat find_best_sample_fmt_of_2 (enum AVSampleFormat dst_fmt1, enum AVSampleFormat dst_fmt2, enum AVSampleFormat src_fmt)
 
int ff_fmt_is_regular_yuv (enum AVPixelFormat fmt)
 Returns true if a pixel format is "regular YUV", which includes all pixel formats that are affected by YUV colorspace negotiation. More...
 
int ff_fmt_is_forced_full_range (enum AVPixelFormat fmt)
 Returns true if a YUV pixel format is forced full range (i.e. More...
 
static int pick_format (AVFilterLink *link, AVFilterLink *ref)
 
static int reduce_formats_on_filter (AVFilterContext *filter)
 
static int reduce_formats (AVFilterGraph *graph)
 
static void swap_samplerates_on_filter (AVFilterContext *filter)
 
static void swap_samplerates (AVFilterGraph *graph)
 
static void swap_channel_layouts_on_filter (AVFilterContext *filter)
 
static void swap_channel_layouts (AVFilterGraph *graph)
 
static void swap_sample_fmts_on_filter (AVFilterContext *filter)
 
static void swap_sample_fmts (AVFilterGraph *graph)
 
static int pick_formats (AVFilterGraph *graph)
 
static int graph_config_formats (AVFilterGraph *graph, void *log_ctx)
 Configure the formats of all the links in the graph. More...
 
static int graph_config_pointers (AVFilterGraph *graph, void *log_ctx)
 
int avfilter_graph_config (AVFilterGraph *graphctx, void *log_ctx)
 Check validity and configure all the links and formats in the graph. More...
 
int avfilter_graph_send_command (AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
 Send a command to one or more filter instances. More...
 
int avfilter_graph_queue_command (AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
 Queue a command for one or more filter instances. More...
 
static void heap_bubble_up (FFFilterGraph *graph, FilterLinkInternal *li, int index)
 
static void heap_bubble_down (FFFilterGraph *graph, FilterLinkInternal *li, int index)
 
void ff_avfilter_graph_update_heap (AVFilterGraph *graph, FilterLinkInternal *li)
 Update the position of a link in the age heap. More...
 
int avfilter_graph_request_oldest (AVFilterGraph *graph)
 Request a frame on the oldest sink link. More...
 
int ff_filter_graph_run_once (AVFilterGraph *graph)
 Run one round of processing on a filter graph. More...
 

Variables

static const AVOption filtergraph_options []
 
static const AVClass filtergraph_class
 
static const uint64_t ch_subst [][2]
 

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   x)    offsetof(AVFilterGraph, x)

Definition at line 44 of file avfiltergraph.c.

◆ F

Definition at line 45 of file avfiltergraph.c.

◆ V

#define V   AV_OPT_FLAG_VIDEO_PARAM

Definition at line 46 of file avfiltergraph.c.

◆ A

#define A   AV_OPT_FLAG_AUDIO_PARAM

Definition at line 47 of file avfiltergraph.c.

◆ MERGE

#define MERGE (   merger,
  link 
)
Value:
((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))

◆ REDUCE_FORMATS

#define REDUCE_FORMATS (   fmt_type,
  list_type,
  list,
  var,
  nb,
  add_format 
)

Definition at line 805 of file avfiltergraph.c.

◆ CH_CENTER_PAIR

Definition at line 966 of file avfiltergraph.c.

◆ CH_FRONT_PAIR

#define CH_FRONT_PAIR   (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)

Definition at line 967 of file avfiltergraph.c.

◆ CH_STEREO_PAIR

#define CH_STEREO_PAIR   (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)

Definition at line 968 of file avfiltergraph.c.

◆ CH_WIDE_PAIR

#define CH_WIDE_PAIR   (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)

Definition at line 969 of file avfiltergraph.c.

◆ CH_SIDE_PAIR

#define CH_SIDE_PAIR   (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)

Definition at line 970 of file avfiltergraph.c.

◆ CH_DIRECT_PAIR

Definition at line 971 of file avfiltergraph.c.

◆ CH_BACK_PAIR

#define CH_BACK_PAIR   (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)

Definition at line 972 of file avfiltergraph.c.

Function Documentation

◆ ff_graph_thread_free()

void ff_graph_thread_free ( FFFilterGraph graph)

Definition at line 71 of file avfiltergraph.c.

Referenced by avfilter_graph_free().

◆ ff_graph_thread_init()

int ff_graph_thread_init ( FFFilterGraph graph)

Definition at line 75 of file avfiltergraph.c.

Referenced by avfilter_graph_alloc_filter().

◆ ff_filter_graph_remove_filter()

void ff_filter_graph_remove_filter ( AVFilterGraph graph,
AVFilterContext filter 
)

Remove a filter from a graph;.

Definition at line 99 of file avfiltergraph.c.

Referenced by avfilter_free().

◆ graph_check_validity()

static int graph_check_validity ( AVFilterGraph graph,
void *  log_ctx 
)
static

Check for the validity of graph.

A graph is considered valid if all its input and output pads are connected.

Returns
>= 0 in case of success, a negative value otherwise

Definition at line 208 of file avfiltergraph.c.

Referenced by avfilter_graph_config().

◆ graph_config_links()

static int graph_config_links ( AVFilterGraph graph,
void *  log_ctx 
)
static

Configure all the links of graphctx.

Returns
>= 0 in case of success, a negative value otherwise

Definition at line 246 of file avfiltergraph.c.

Referenced by avfilter_graph_config().

◆ graph_check_links()

static int graph_check_links ( AVFilterGraph graph,
void *  log_ctx 
)
static

Definition at line 263 of file avfiltergraph.c.

Referenced by avfilter_graph_config().

◆ filter_link_check_formats()

static int filter_link_check_formats ( void *  log,
AVFilterLink link,
AVFilterFormatsConfig cfg 
)
static

Definition at line 295 of file avfiltergraph.c.

Referenced by filter_check_formats().

◆ filter_check_formats()

static int filter_check_formats ( AVFilterContext ctx)
static

Check the validity of the formats / etc.

lists set by query_formats().

In particular, check they do not contain any redundant element.

Definition at line 326 of file avfiltergraph.c.

Referenced by filter_query_formats().

◆ filter_query_formats()

static int filter_query_formats ( AVFilterContext ctx)
static

Definition at line 344 of file avfiltergraph.c.

Referenced by query_formats().

◆ formats_declared()

static int formats_declared ( AVFilterContext f)
static

Definition at line 409 of file avfiltergraph.c.

Referenced by query_formats().

◆ query_formats()

static int query_formats ( AVFilterGraph graph,
void *  log_ctx 
)
static

Perform one round of query_formats() and merging formats lists on the filter graph.

Returns
>=0 if all links formats lists could be queried and merged; AVERROR(EAGAIN) some progress was made in the queries or merging and a later call may succeed; AVERROR(EIO) (may be changed) plus a log message if no progress was made and the negotiation is stuck; a negative error code if some other error happened

Definition at line 450 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ get_fmt_score()

static int get_fmt_score ( enum AVSampleFormat  dst_fmt,
enum AVSampleFormat  src_fmt 
)
static

Definition at line 617 of file avfiltergraph.c.

Referenced by find_best_sample_fmt_of_2().

◆ find_best_sample_fmt_of_2()

static enum AVSampleFormat find_best_sample_fmt_of_2 ( enum AVSampleFormat  dst_fmt1,
enum AVSampleFormat  dst_fmt2,
enum AVSampleFormat  src_fmt 
)
static

Definition at line 640 of file avfiltergraph.c.

Referenced by pick_format().

◆ ff_fmt_is_regular_yuv()

int ff_fmt_is_regular_yuv ( enum AVPixelFormat  fmt)

Returns true if a pixel format is "regular YUV", which includes all pixel formats that are affected by YUV colorspace negotiation.

Definition at line 651 of file avfiltergraph.c.

Referenced by pick_format(), and query_formats().

◆ ff_fmt_is_forced_full_range()

int ff_fmt_is_forced_full_range ( enum AVPixelFormat  fmt)

Returns true if a YUV pixel format is forced full range (i.e.

YUVJ).

Definition at line 664 of file avfiltergraph.c.

Referenced by pick_format(), and query_formats().

◆ pick_format()

static int pick_format ( AVFilterLink link,
AVFilterLink ref 
)
static

Definition at line 678 of file avfiltergraph.c.

Referenced by pick_formats().

◆ reduce_formats_on_filter()

static int reduce_formats_on_filter ( AVFilterContext filter)
static

Definition at line 842 of file avfiltergraph.c.

Referenced by reduce_formats().

◆ reduce_formats()

static int reduce_formats ( AVFilterGraph graph)
static

Definition at line 900 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ swap_samplerates_on_filter()

static void swap_samplerates_on_filter ( AVFilterContext filter)
static

Definition at line 917 of file avfiltergraph.c.

Referenced by swap_samplerates().

◆ swap_samplerates()

static void swap_samplerates ( AVFilterGraph graph)
static

Definition at line 958 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ swap_channel_layouts_on_filter()

static void swap_channel_layouts_on_filter ( AVFilterContext filter)
static

Definition at line 1000 of file avfiltergraph.c.

Referenced by swap_channel_layouts().

◆ swap_channel_layouts()

static void swap_channel_layouts ( AVFilterGraph graph)
static

Definition at line 1094 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ swap_sample_fmts_on_filter()

static void swap_sample_fmts_on_filter ( AVFilterContext filter)
static

Definition at line 1102 of file avfiltergraph.c.

Referenced by swap_sample_fmts().

◆ swap_sample_fmts()

static void swap_sample_fmts ( AVFilterGraph graph)
static

Definition at line 1162 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ pick_formats()

static int pick_formats ( AVFilterGraph graph)
static

Definition at line 1171 of file avfiltergraph.c.

Referenced by graph_config_formats().

◆ graph_config_formats()

static int graph_config_formats ( AVFilterGraph graph,
void *  log_ctx 
)
static

Configure the formats of all the links in the graph.

Definition at line 1226 of file avfiltergraph.c.

Referenced by avfilter_graph_config().

◆ graph_config_pointers()

static int graph_config_pointers ( AVFilterGraph graph,
void *  log_ctx 
)
static

Definition at line 1254 of file avfiltergraph.c.

Referenced by avfilter_graph_config().

◆ heap_bubble_up()

static void heap_bubble_up ( FFFilterGraph graph,
FilterLinkInternal li,
int  index 
)
static

Definition at line 1374 of file avfiltergraph.c.

Referenced by ff_avfilter_graph_update_heap().

◆ heap_bubble_down()

static void heap_bubble_down ( FFFilterGraph graph,
FilterLinkInternal li,
int  index 
)
static

◆ ff_avfilter_graph_update_heap()

void ff_avfilter_graph_update_heap ( AVFilterGraph graph,
FilterLinkInternal li 
)

Update the position of a link in the age heap.

Definition at line 1417 of file avfiltergraph.c.

Referenced by update_link_current_pts().

◆ ff_filter_graph_run_once()

int ff_filter_graph_run_once ( AVFilterGraph graph)

Run one round of processing on a filter graph.

Definition at line 1472 of file avfiltergraph.c.

Referenced by avfilter_graph_request_oldest(), get_frame_internal(), and push_frame().

Variable Documentation

◆ filtergraph_options

const AVOption filtergraph_options[]
static
Initial value:
= {
{ "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
{ .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, F|V|A, .unit = "thread_type" },
{ "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = F|V|A, .unit = "thread_type" },
{ "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT,
{ .i64 = 0 }, 0, INT_MAX, F|V|A, .unit = "threads"},
{"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"},
{"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V },
{"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|A },
{ NULL },
}

Definition at line 48 of file avfiltergraph.c.

◆ filtergraph_class

const AVClass filtergraph_class
static
Initial value:
= {
.class_name = "AVFilterGraph",
.item_name = av_default_item_name,
}

Definition at line 62 of file avfiltergraph.c.

Referenced by avfilter_graph_alloc().

◆ ch_subst

const uint64_t ch_subst[][2]
static
F
#define F
Definition: avfiltergraph.c:45
merge
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
Definition: bink.c:221
OFFSET
#define OFFSET(x)
Definition: avfiltergraph.c:44
AVFILTER_THREAD_SLICE
#define AVFILTER_THREAD_SLICE
Process multiple parts of the frame concurrently.
Definition: avfilter.h:454
filtergraph_options
static const AVOption filtergraph_options[]
Definition: avfiltergraph.c:48
CH_DIRECT_PAIR
#define CH_DIRECT_PAIR
Definition: avfiltergraph.c:971
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
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
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:177
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
CH_BACK_PAIR
#define CH_BACK_PAIR
Definition: avfiltergraph.c:972
CH_CENTER_PAIR
#define CH_CENTER_PAIR
Definition: avfiltergraph.c:966
offset
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 offset
Definition: writing_filters.txt:86
CH_FRONT_PAIR
#define CH_FRONT_PAIR
Definition: avfiltergraph.c:967
AV_CH_BACK_CENTER
#define AV_CH_BACK_CENTER
Definition: channel_layout.h:183
V
#define V
Definition: avfiltergraph.c:46
CH_SIDE_PAIR
#define CH_SIDE_PAIR
Definition: avfiltergraph.c:970
CH_WIDE_PAIR
#define CH_WIDE_PAIR
Definition: avfiltergraph.c:969
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
A
#define A
Definition: avfiltergraph.c:47
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
FF_FIELD_AT
#define FF_FIELD_AT(type, off, obj)
Access a field in a structure by its offset.
Definition: internal.h:85
AV_OPT_TYPE_STRING
@ 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:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299