41 #define DEF_CHOOSE_FORMAT(suffix, type, var, supported_list, none, get_name) \ 42 static char *choose_ ## suffix (OutputFilter *ofilter) \ 44 if (ofilter->var != none) { \ 45 get_name(ofilter->var); \ 46 return av_strdup(name); \ 47 } else if (ofilter->supported_list) { \ 49 AVIOContext *s = NULL; \ 53 if (avio_open_dyn_buf(&s) < 0) \ 56 for (p = ofilter->supported_list; *p != none; p++) { \ 58 avio_printf(s, "%s|", name); \ 60 len = avio_close_dyn_buf(s, &ret); \ 108 ist->filters[ist->nb_filters - 1] = fg->
inputs[0];
133 int file_idx = strtol(in->
name, &p, 0);
163 if (i == nb_input_streams) {
165 "unlabeled input pad %d on filter %s\n", in->
pad_idx,
207 for (cur = inputs; cur; cur = cur->
next)
210 for (cur = outputs; cur;) {
247 "recording time.\n", name);
255 if (duration != INT64_MAX) {
290 filter_name, args,
NULL, graph);
313 snprintf(name,
sizeof(name),
"output stream %d:%d", ost->
file_index, ost->
index);
324 snprintf(args,
sizeof(args),
"%d:%d:0x%X",
327 snprintf(name,
sizeof(name),
"scaler for output stream %d:%d",
332 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
339 if ((pix_fmts = choose_pix_fmts(ofilter))) {
341 snprintf(name,
sizeof(name),
"pixel format for output stream %d:%d",
349 if ((ret =
avfilter_link(last_filter, pad_idx, filter, 0)) < 0)
360 snprintf(args,
sizeof(args),
"fps=%d/%d", ost->
frame_rate.
num,
362 snprintf(name,
sizeof(name),
"fps for output stream %d:%d",
376 snprintf(name,
sizeof(name),
"trim for output stream %d:%d",
379 &last_filter, &pad_idx, name);
397 char *
sample_fmts, *sample_rates, *channel_layouts;
402 snprintf(name,
sizeof(name),
"output stream %d:%d", ost->
file_index, ost->
index);
412 sample_fmts = choose_sample_fmts(ofilter);
413 sample_rates = choose_sample_rates(ofilter);
414 channel_layouts = choose_channel_layouts(ofilter);
415 if (sample_fmts || sample_rates || channel_layouts) {
421 len += snprintf(args + len,
sizeof(args) - len,
"sample_fmts=%s:",
424 len += snprintf(args + len,
sizeof(args) - len,
"sample_rates=%s:",
427 len += snprintf(args + len,
sizeof(args) - len,
"channel_layouts=%s:",
435 snprintf(name,
sizeof(name),
"audio format for output stream %d:%d",
451 snprintf(name,
sizeof(name),
"trim for output stream %d:%d",
454 &last_filter, &pad_idx, name);
464 #define DESCRIBE_FILTER_LINK(f, inout, in) \ 466 AVFilterContext *ctx = inout->filter_ctx; \ 467 AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \ 468 int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; \ 471 if (avio_open_dyn_buf(&pb) < 0) \ 474 avio_printf(pb, "%s", ctx->filter->name); \ 476 avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\ 478 avio_close_dyn_buf(pb, &f->name); \ 504 int ret, pad_idx = 0;
506 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
535 last_filter = ifilter->
filter;
542 if (rot < -135 || rot > 135) {
547 }
else if (rot < -45) {
548 ret =
insert_filter(&last_filter, &pad_idx,
"transpose",
"dir=clock");
549 }
else if (rot > 45) {
550 ret =
insert_filter(&last_filter, &pad_idx,
"transpose",
"dir=cclock");
557 snprintf(name,
sizeof(name),
"trim for input stream %d:%d",
577 char args[255],
name[255];
578 int ret, pad_idx = 0;
580 snprintf(name,
sizeof(name),
"graph %d input from stream %d:%d", fg->
index,
604 last_filter = ifilter->
filter;
611 "asyncts audio filter instead.\n");
614 len += snprintf(args + len,
sizeof(args) - len,
"compensate=1:" 616 snprintf(args + len,
sizeof(args) - len,
"min_delta=%f",
619 snprintf(name,
sizeof(name),
"graph %d audio sync for input stream %d:%d",
637 "audio filter instead.\n");
639 snprintf(args,
sizeof(args),
"volume=%f",
audio_volume / 256.0);
641 snprintf(name,
sizeof(name),
"graph %d volume for input stream %d:%d",
653 last_filter = volume;
656 snprintf(name,
sizeof(name),
"trim for input stream %d:%d",
698 snprintf(args,
sizeof(args),
"flags=0x%X", (
unsigned)ost->
sws_flags);
707 args[strlen(args) - 1] =
'\0';
720 if (simple && (!inputs || inputs->
next || !outputs || outputs->
next)) {
722 "exactly one input and output.\n", graph_desc);
726 for (cur = inputs, i = 0; cur; cur = cur->
next, i++)
731 for (cur = outputs, i = 0; cur; cur = cur->
next, i++) {
static int insert_filter(AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
AVFilterContext ** filters
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
static const char * filter_name(void *p)
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
Main libavfilter public API header.
Memory buffer source API.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
int h
agreed upon image height
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
int index
stream index in AVFormatContext
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static enum AVSampleFormat formats[]
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in...
uint8_t * av_stream_get_side_data(AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
FilterGraph ** filtergraphs
AVRational frame_rate
Video only, the frame rate of the input video.
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int configure_filtergraph(FilterGraph *fg)
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
AVRational sample_aspect_ratio
Video only, the sample (pixel) aspect ratio.
AVFilterLink ** inputs
array of pointers to input links
char * name
name of this filter instance
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
AVFilterPad * output_pads
array of output pads
float audio_drift_threshold
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
AVRational time_base
The timebase to be used for the timestamps on the input frames.
#define DESCRIBE_FILTER_LINK(f, inout, in)
AVStream ** streams
A list of all streams in the file.
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
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.
char * resample_lavr_opts
libavresample options to use for the auto-inserted resample filters
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVDictionary * resample_opts
int sample_rate
Audio only, the audio sampling rate in samples per secon.
int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs)
Add a graph described by a string to a graph.
A link between two filters.
AVFilterPad * input_pads
array of input pads
static int64_t start_time
static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define GET_CH_LAYOUT_NAME(ch_layout)
int sample_rate
samples per second
uint64_t channel_layout
Audio only, the audio channel layout.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
enum AVMediaType codec_type
General type of the encoded data.
simple assert() macros that are a bit more flexible than ISO C assert().
int format
video: the pixel format, value corresponds to enum AVPixelFormat audio: the sample format...
static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
Audio channel layout.
uint64_t channel_layout
Channel layout of the audio data.
int w
agreed upon image width
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
#define DEF_CHOOSE_FORMAT(suffix, type, var, supported_list, none, get_name)
audio channel layout utility functions
This structure contains the parameters describing the frames that will be passed to this filter...
static int insert_trim(int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
struct OutputStream * ost
#define GET_PIX_FMT_NAME(pix_fmt)
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
static void init_input_filter(FilterGraph *fg, AVFilterInOut *in)
AVBufferRef * hw_device_ctx
#define GET_SAMPLE_FMT_NAME(sample_fmt)
AVFilterContext * filter_ctx
filter context associated to this input/output
int format
agreed upon media format
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
A linked-list of the inputs/outputs of the filter chain.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define GET_SAMPLE_RATE_NAME(rate)
AVBufferRef * hw_frames_ctx
Video with a hwaccel pixel format only.
int init_complex_filtergraph(FilterGraph *fg)
OutputFile ** output_files
enum AVMediaType codec_type
AVSampleFormat
Audio Sample Formats.
char * av_strdup(const char *s)
Duplicate the string s.
main external API structure.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int filtergraph_is_simple(FilterGraph *fg)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int sample_rate
Sample rate of the audio data.
static const AVFilterPad inputs[]
int pad_idx
index of the filt_ctx pad to use for linking
rational number numerator/denominator
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
static enum AVPixelFormat pix_fmts[]
char * name
unique name for this input/output in the list
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
#define AVERROR_FILTER_NOT_FOUND
Filter not found.
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
int av_fifo_size(AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
struct FilterGraph * graph
InputStream ** input_streams
int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param)
Initialize the buffersrc or abuffersrc filter with the provided parameters.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
double av_display_rotation_get(const int32_t matrix[9])
The display transformation matrix specifies an affine transformation that should be applied to video ...
#define GROW_ARRAY(array, nb_elems)
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
int channels
number of audio channels
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
AVBufferSrcParameters * av_buffersrc_parameters_alloc(void)
Allocate a new AVBufferSrcParameters instance.
static enum AVSampleFormat sample_fmts[]
#define AV_DICT_IGNORE_SUFFIX
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
AVCodecParameters * codecpar
int width
Video only, the display dimensions of the input frames.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVPixelFormat
Pixel format.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AV_NOPTS_VALUE
Undefined timestamp value.
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist)