Go to the documentation of this file.
48 if (!strcmp(codec->
name,
"mjpeg")) {
51 return default_formats;
62 int has_alpha =
desc ?
desc->nb_components % 2 == 0 : 0;
76 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
97 if (
ost->keep_pix_fmt) {
106 }
else if (
ost->enc &&
ost->enc->pix_fmts) {
109 p =
ost->enc->pix_fmts;
127 #define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name) \
128 static void choose_ ## name (OutputFilter *ofilter, AVBPrint *bprint) \
130 if (ofilter->var == none && !ofilter->supported_list) \
132 av_bprintf(bprint, #name "="); \
133 if (ofilter->var != none) { \
134 av_bprintf(bprint, printf_format, get_name(ofilter->var)); \
138 for (p = ofilter->supported_list; *p != none; p++) { \
139 av_bprintf(bprint, printf_format "|", get_name(*p)); \
141 if (bprint->len > 0) \
142 bprint->str[--bprint->len] = '\0'; \
144 av_bprint_chars(bprint, ':', 1); \
161 }
else if (ofilter->ch_layouts) {
165 for (p = ofilter->ch_layouts; p->
nb_channels; p++) {
170 bprint->str[--bprint->len] =
'\0';
191 ost->filter = ofilter;
215 int nb_pads = in ?
ctx->nb_inputs :
ctx->nb_outputs;
246 int file_idx = strtol(in->
name, &p, 0);
255 for (
i = 0;
i <
s->nb_streams;
i++) {
256 enum AVMediaType stream_type =
s->streams[
i]->codecpar->codec_type;
257 if (stream_type !=
type &&
274 "matches a disabled input stream.\n", p, fg->
graph_desc);
288 "unlabeled input pad %d on filter %s\n", in->
pad_idx,
355 const char *filter_name)
370 "recording time.\n",
name);
405 const char *filter_name,
const char *args)
413 filter_name, args,
NULL, graph);
432 int pad_idx =
out->pad_idx;
450 snprintf(args,
sizeof(args),
"%d:%d",
487 if (
ost->frame_rate.num && 0) {
491 snprintf(args,
sizeof(args),
"fps=%d/%d",
ost->frame_rate.num,
492 ost->frame_rate.den);
510 &last_filter, &pad_idx,
name);
527 int pad_idx =
out->pad_idx;
541 #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \
542 AVFilterContext *filt_ctx; \
544 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
545 "similarly to -af " filter_name "=%s.\n", arg); \
547 ret = avfilter_graph_create_filter(&filt_ctx, \
548 avfilter_get_by_name(filter_name), \
549 filter_name, arg, NULL, fg->graph); \
553 ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
557 last_filter = filt_ctx; \
561 if (
ost->audio_channels_mapped) {
566 for (
i = 0;
i <
ost->audio_channels_mapped;
i++)
567 if (
ost->audio_channels_map[
i] != -1)
577 choose_sample_fmts(ofilter, &args);
578 choose_sample_rates(ofilter, &args);
618 &last_filter, &pad_idx,
name);
721 int ret, pad_idx = 0;
722 int64_t tsoffset = 0;
727 memset(par, 0,
sizeof(*par));
750 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:"
751 "pixel_aspect=%d/%d",
768 last_filter = ifilter->
filter;
782 if (
fabs(theta - 90) < 1.0) {
784 displaymatrix[3] > 0 ?
"cclock_flip" :
"clock");
785 }
else if (
fabs(theta - 180) < 1.0) {
786 if (displaymatrix[0] < 0) {
791 if (displaymatrix[4] < 0) {
794 }
else if (
fabs(theta - 270) < 1.0) {
796 displaymatrix[3] < 0 ?
"clock_flip" :
"cclock");
797 }
else if (
fabs(theta) > 1.0) {
799 snprintf(rotate_buf,
sizeof(rotate_buf),
"%f*PI/180", theta);
801 }
else if (
fabs(theta) < 1.0) {
802 if (displaymatrix && displaymatrix[4] < 0) {
815 tsoffset +=
f->ctx->start_time;
819 &last_filter, &pad_idx,
name);
841 int ret, pad_idx = 0;
842 int64_t tsoffset = 0;
850 av_bprintf(&args,
"time_base=%d/%d:sample_rate=%d:sample_fmt=%s",
867 last_filter = ifilter->
filter;
869 #define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg) do { \
870 AVFilterContext *filt_ctx; \
872 av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
873 "similarly to -af " filter_name "=%s.\n", arg); \
875 snprintf(name, sizeof(name), "graph_%d_%s_in_%d_%d", \
876 fg->index, filter_name, ist->file_index, ist->st->index); \
877 ret = avfilter_graph_create_filter(&filt_ctx, \
878 avfilter_get_by_name(filter_name), \
879 name, arg, NULL, fg->graph); \
883 ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
887 last_filter = filt_ctx; \
891 char args[256] = {0};
918 "audio filter instead.\n");
929 tsoffset +=
f->ctx->start_time;
933 &last_filter, &pad_idx,
name);
948 "No decoder for stream #%d:%d, filtering impossible\n",
971 return f->nb_inputs == 0 &&
972 (!strcmp(
f->filter->name,
"buffer") ||
973 !strcmp(
f->filter->name,
"abuffer"));
986 f->nb_outputs == 0 ||
1026 args[strlen(args)-1] = 0;
1037 args[strlen(args)-1] = 0;
1051 const char *num_inputs;
1052 const char *num_outputs;
1062 }
else if (
inputs->next) {
1068 "to have exactly 1 input and 1 output."
1069 " However, it had %s input(s) and %s output(s)."
1070 " Please adjust, or use a complex filtergraph (-filter_complex) instead.\n",
1071 graph_desc, num_inputs, num_outputs);
1128 ost->enc_ctx->frame_size);
1192 if (
frame->hw_frames_ctx) {
int init_complex_filtergraph(FilterGraph *fg)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_BPRINT_SIZE_UNLIMITED
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
AVPixelFormat
Pixel format.
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
struct FilterGraph * graph
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
int nb_threads
Maximum number of threads used by filters in this graph.
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
#define ALLOC_ARRAY_ELEM(array, nb_elems)
static enum AVSampleFormat sample_fmts[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
char * av_asprintf(const char *fmt,...)
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int64_t start_time
start time in microseconds == AV_TIME_BASE units
This structure describes decoded (raw) audio or video data.
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
AVStream ** streams
A list of all streams in the file.
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
void check_filter_outputs(void)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
enum AVChannelOrder order
Channel order used in this layout.
AVFilterPad * output_pads
array of output pads
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
int nb_channels
Number of channels in this layout.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int configure_filtergraph(FilterGraph *fg)
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
AVChannelLayout ch_layout
Audio channel layout.
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
@ AVDISCARD_NONE
discard nothing
#define AV_BPRINT_SIZE_AUTOMATIC
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 type
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static int graph_is_meta(AVFilterGraph *graph)
A filter pad used for either input or output.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVFilterPad * input_pads
array of input pads
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AVFILTER_AUTO_CONVERT_NONE
all automatic conversions disabled
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
InputStream ** input_streams
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
int av_buffersink_get_format(const AVFilterContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
struct OutputStream * ost
float audio_drift_threshold
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AVDISCARD_ALL
discard all
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static __device__ float fabs(float a)
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
Enable or disable automatic format conversion inside the graph.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
AVFilterContext ** filters
char * name
name of this filter instance
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int pad_idx
index of the filt_ctx pad to use for linking
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
An AVChannelLayout holds information about the channel layout of audio data.
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
AVFilterContext * filter_ctx
filter context associated to this input/output
OutputFile ** output_files
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
AVBufferRef * hw_frames_ctx
Video with a hwaccel pixel format only.
static int64_t start_time
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
void sub2video_update(InputStream *ist, int64_t heartbeat_pts, AVSubtitle *sub)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
static int filter_is_buffersrc(const AVFilterContext *f)
#define AV_LOG_INFO
Standard information.
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
static enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *enc_ctx, const AVCodec *codec, enum AVPixelFormat target)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
int av_buffersink_get_w(const AVFilterContext *ctx)
int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param)
Initialize the buffersrc or abuffersrc filter with the provided parameters.
#define DECODING_FOR_FILTER
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
#define i(width, name, range_min, range_max)
static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
AVSampleFormat
Audio sample formats.
int hw_device_setup_for_filter(FilterGraph *fg)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
FilterGraph ** filtergraphs
int av_buffersink_get_h(const AVFilterContext *ctx)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
AVChannelLayout ch_layout
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
uint8_t * av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static enum AVPixelFormat * get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[])
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
main external API structure.
int index
stream index in AVFormatContext
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Compute what kind of losses will occur when converting from one specific pixel format to another.
#define DEF_CHOOSE_FORMAT(name, type, var, supported_list, none, printf_format, get_name)
This structure contains the parameters describing the frames that will be passed to this filter.
int av_buffersink_get_sample_rate(const AVFilterContext *ctx)
int format
video: the pixel format, value corresponds to enum AVPixelFormat audio: the sample format,...
static char * describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in)
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
#define GROW_ARRAY(array, nb_elems)
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
static void cleanup_filtergraph(FilterGraph *fg)
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate a string.
int auto_conversion_filters
Structure to hold side data for an AVFrame.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const char * choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int filtergraph_is_simple(FilterGraph *fg)
char * name
unique name for this input/output in the list
int width
picture width / height.
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
double get_rotation(int32_t *displaymatrix)
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
A linked-list of the inputs/outputs of the filter chain.
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
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.
int filter_complex_nbthreads
static int sub2video_prepare(InputStream *ist, InputFilter *ifilter)