FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
ffmpeg_filter.c File Reference
#include <stdint.h>
#include "ffmpeg.h"
#include "libavfilter/avfilter.h"
#include "libavfilter/buffersink.h"
#include "libavresample/avresample.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/display.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "libavutil/imgutils.h"
#include "libavutil/samplefmt.h"

Go to the source code of this file.

Macros

#define DEF_CHOOSE_FORMAT(type, var, supported_list, none, get_name)
 
#define AUTO_INSERT_FILTER(opt_name, filter_name, arg)
 
#define DESCRIBE_FILTER_LINK(f, inout, in)
 
#define AUTO_INSERT_FILTER_INPUT(opt_name, filter_name, arg)
 

Functions

enum AVPixelFormat choose_pixel_fmt (AVStream *st, AVCodecContext *enc_ctx, AVCodec *codec, enum AVPixelFormat target)
 
void choose_sample_fmt (AVStream *st, AVCodec *codec)
 
static char * choose_pix_fmts (OutputStream *ost)
 
 DEF_CHOOSE_FORMAT (enum AVSampleFormat, sample_fmt, sample_fmts, AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME) DEF_CHOOSE_FORMAT(int
 
GET_SAMPLE_RATE_NAME DEF_CHOOSE_FORMAT (uint64_t, channel_layout, channel_layouts, 0, GET_CH_LAYOUT_NAME)
 
static void init_input_filter (FilterGraph *fg, AVFilterInOut *in)
 
int init_complex_filtergraph (FilterGraph *fg)
 
static int insert_trim (int64_t start_time, int64_t duration, AVFilterContext **last_filter, int *pad_idx, const char *filter_name)
 
static int insert_filter (AVFilterContext **last_filter, int *pad_idx, const char *filter_name, const char *args)
 
static int configure_output_video_filter (FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
 
static int configure_output_audio_filter (FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
 
int configure_output_filter (FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out)
 
static int sub2video_prepare (InputStream *ist)
 
static int configure_input_video_filter (FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
 
static int configure_input_audio_filter (FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
 
static int configure_input_filter (FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in)
 
int configure_filtergraph (FilterGraph *fg)
 
int ist_in_filtergraph (FilterGraph *fg, InputStream *ist)
 

Variables

 sample_rate
 
 supported_samplerates
 

Macro Definition Documentation

#define DEF_CHOOSE_FORMAT (   type,
  var,
  supported_list,
  none,
  get_name 
)
Value:
static char *choose_ ## var ## s(OutputStream *ost) \
{ \
if (ost->enc_ctx->var != none) { \
get_name(ost->enc_ctx->var); \
} else if (ost->enc && ost->enc->supported_list) { \
const type *p; \
AVIOContext *s = NULL; \
uint8_t *ret; \
int len; \
for (p = ost->enc->supported_list; *p != none; p++) { \
get_name(*p); \
avio_printf(s, "%s|", name); \
} \
len = avio_close_dyn_buf(s, &ret); \
ret[len - 1] = 0; \
return ret; \
}
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1146
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1134
uint8_t
return
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:116
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
GLint GLenum type
Definition: opengl_enc.c:105
if(ret< 0)
Definition: vf_mcdeint.c:280
int len
for(j=16;j >0;--j)
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
const char * name
Definition: opengl_enc.c:103

Definition at line 150 of file ffmpeg_filter.c.

#define AUTO_INSERT_FILTER (   opt_name,
  filter_name,
  arg 
)
Value:
do { \
AVFilterContext *filt_ctx; \
av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
"similarly to -af " filter_name "=%s.\n", arg); \
\
ret = avfilter_graph_create_filter(&filt_ctx, \
avfilter_get_by_name(filter_name), \
filter_name, arg, NULL, fg->graph); \
if (ret < 0) \
return ret; \
\
ret = avfilter_link(last_filter, pad_idx, filt_ctx, 0); \
if (ret < 0) \
return ret; \
\
last_filter = filt_ctx; \
pad_idx = 0; \
} while (0)
#define NULL
Definition: coverity.c:32
static AVFilter ** last_filter
Definition: avfilter.c:482
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:131
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.
#define av_log(a,...)
const char * arg
Definition: jacosubdec.c:66
return
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:487
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
if(ret< 0)
Definition: vf_mcdeint.c:280

Referenced by configure_output_audio_filter().

#define DESCRIBE_FILTER_LINK (   f,
  inout,
  in 
)
Value:
{ \
AVFilterContext *ctx = inout->filter_ctx; \
AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; \
int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; \
AVIOContext *pb; \
avio_printf(pb, "%s", ctx->filter->name); \
if (nb_pads > 1) \
avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\
avio_w8(pb, 0); \
avio_close_dyn_buf(pb, &f->name); \
}
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1146
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1134
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:116
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:156
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:1004
if(ret< 0)
Definition: vf_mcdeint.c:280
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2

Definition at line 628 of file ffmpeg_filter.c.

Referenced by configure_input_filter(), and configure_output_filter().

#define AUTO_INSERT_FILTER_INPUT (   opt_name,
  filter_name,
  arg 
)
Value:
do { \
AVFilterContext *filt_ctx; \
av_log(NULL, AV_LOG_INFO, opt_name " is forwarded to lavfi " \
"similarly to -af " filter_name "=%s.\n", arg); \
snprintf(name, sizeof(name), "graph %d %s for input stream %d:%d", \
fg->index, filter_name, ist->file_index, ist->st->index); \
ret = avfilter_graph_create_filter(&filt_ctx, \
avfilter_get_by_name(filter_name), \
name, arg, NULL, fg->graph); \
if (ret < 0) \
return ret; \
\
ret = avfilter_link(last_filter, 0, filt_ctx, 0); \
if (ret < 0) \
return ret; \
\
last_filter = filt_ctx; \
} while (0)
#define NULL
Definition: coverity.c:32
static AVFilter ** last_filter
Definition: avfilter.c:482
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
Definition: avfilter.c:131
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.
#define av_log(a,...)
const char * arg
Definition: jacosubdec.c:66
return
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:487
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
#define snprintf
Definition: snprintf.h:34
if(ret< 0)
Definition: vf_mcdeint.c:280
const char * name
Definition: opengl_enc.c:103

Referenced by configure_input_audio_filter().

Function Documentation

enum AVPixelFormat choose_pixel_fmt ( AVStream st,
AVCodecContext enc_ctx,
AVCodec codec,
enum AVPixelFormat  target 
)

Definition at line 41 of file ffmpeg_filter.c.

Referenced by choose_pix_fmts(), and read_ffserver_streams().

void choose_sample_fmt ( AVStream st,
AVCodec codec 
)

Definition at line 79 of file ffmpeg_filter.c.

Referenced by read_ffserver_streams().

static char* choose_pix_fmts ( OutputStream ost)
static

Definition at line 101 of file ffmpeg_filter.c.

Referenced by configure_output_video_filter().

DEF_CHOOSE_FORMAT ( enum  AVSampleFormat,
sample_fmt  ,
sample_fmts  ,
AV_SAMPLE_FMT_NONE  ,
GET_SAMPLE_FMT_NAME   
)
GET_SAMPLE_RATE_NAME DEF_CHOOSE_FORMAT ( uint64_t  ,
channel_layout  ,
channel_layouts  ,
,
GET_CH_LAYOUT_NAME   
)

Definition at line 185 of file ffmpeg_filter.c.

static void init_input_filter ( FilterGraph fg,
AVFilterInOut in 
)
static

Definition at line 219 of file ffmpeg_filter.c.

Referenced by init_complex_filtergraph().

int init_complex_filtergraph ( FilterGraph fg)

Definition at line 292 of file ffmpeg_filter.c.

Referenced by init_complex_filters().

static int insert_trim ( int64_t  start_time,
int64_t  duration,
AVFilterContext **  last_filter,
int *  pad_idx,
const char *  filter_name 
)
static
static int insert_filter ( AVFilterContext **  last_filter,
int *  pad_idx,
const char *  filter_name,
const char *  args 
)
static

Definition at line 382 of file ffmpeg_filter.c.

Referenced by configure_input_video_filter().

static int configure_output_video_filter ( FilterGraph fg,
OutputFilter ofilter,
AVFilterInOut out 
)
static

Definition at line 404 of file ffmpeg_filter.c.

Referenced by configure_output_filter().

static int configure_output_audio_filter ( FilterGraph fg,
OutputFilter ofilter,
AVFilterInOut out 
)
static

Definition at line 500 of file ffmpeg_filter.c.

Referenced by configure_output_filter().

int configure_output_filter ( FilterGraph fg,
OutputFilter ofilter,
AVFilterInOut out 
)

Definition at line 645 of file ffmpeg_filter.c.

Referenced by configure_filtergraph().

static int sub2video_prepare ( InputStream ist)
static

Definition at line 662 of file ffmpeg_filter.c.

Referenced by configure_input_video_filter().

static int configure_input_video_filter ( FilterGraph fg,
InputFilter ifilter,
AVFilterInOut in 
)
static

Definition at line 699 of file ffmpeg_filter.c.

Referenced by configure_input_filter().

static int configure_input_audio_filter ( FilterGraph fg,
InputFilter ifilter,
AVFilterInOut in 
)
static

Definition at line 825 of file ffmpeg_filter.c.

Referenced by configure_input_filter().

static int configure_input_filter ( FilterGraph fg,
InputFilter ifilter,
AVFilterInOut in 
)
static

Definition at line 935 of file ffmpeg_filter.c.

Referenced by configure_filtergraph().

int configure_filtergraph ( FilterGraph fg)
int ist_in_filtergraph ( FilterGraph fg,
InputStream ist 
)

Definition at line 1059 of file ffmpeg_filter.c.

Referenced by decode_audio(), and decode_video().

Variable Documentation

sample_rate
supported_samplerates

Definition at line 182 of file ffmpeg_filter.c.

Referenced by print_codec().