FFmpeg  2.1.1
filtfmts.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdio.h>
22 
23 #include "libavformat/avformat.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/samplefmt.h"
26 #include "libavfilter/avfilter.h"
27 #include "libavfilter/formats.h"
28 
29 static void print_formats(AVFilterContext *filter_ctx)
30 {
31  int i, j;
32 
33 #define PRINT_FMTS(inout, outin, INOUT) \
34  for (i = 0; i < filter_ctx->nb_##inout##puts; i++) { \
35  if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
36  AVFilterFormats *fmts = \
37  filter_ctx->inout##puts[i]->outin##_formats; \
38  for (j = 0; j < fmts->nb_formats; j++) \
39  if(av_get_pix_fmt_name(fmts->formats[j])) \
40  printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
41  i, filter_ctx->filter->inout##puts[i].name, \
42  av_get_pix_fmt_name(fmts->formats[j])); \
43  } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
44  AVFilterFormats *fmts; \
45  AVFilterChannelLayouts *layouts; \
46  \
47  fmts = filter_ctx->inout##puts[i]->outin##_formats; \
48  for (j = 0; j < fmts->nb_formats; j++) \
49  printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
50  i, filter_ctx->filter->inout##puts[i].name, \
51  av_get_sample_fmt_name(fmts->formats[j])); \
52  \
53  layouts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
54  for (j = 0; j < layouts->nb_channel_layouts; j++) { \
55  char buf[256]; \
56  av_get_channel_layout_string(buf, sizeof(buf), -1, \
57  layouts->channel_layouts[j]); \
58  printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
59  i, filter_ctx->filter->inout##puts[i].name, buf); \
60  } \
61  } \
62  } \
63 
64  PRINT_FMTS(in, out, IN);
65  PRINT_FMTS(out, in, OUT);
66 }
67 
68 int main(int argc, char **argv)
69 {
71  AVFilterContext *filter_ctx;
72  AVFilterGraph *graph_ctx;
73  const char *filter_name;
74  const char *filter_args = NULL;
75  int i;
76 
78 
79  if (argc < 2) {
80  fprintf(stderr, "Missing filter name as argument\n");
81  return 1;
82  }
83 
84  filter_name = argv[1];
85  if (argc > 2)
86  filter_args = argv[2];
87 
88  /* allocate graph */
89  graph_ctx = avfilter_graph_alloc();
90  if (!graph_ctx)
91  return 1;
92 
94 
95  /* get a corresponding filter and open it */
96  if (!(filter = avfilter_get_by_name(filter_name))) {
97  fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
98  return 1;
99  }
100 
101  /* open filter and add it to the graph */
102  if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
103  fprintf(stderr, "Impossible to open filter with name '%s'\n",
104  filter_name);
105  return 1;
106  }
107  if (avfilter_init_str(filter_ctx, filter_args) < 0) {
108  fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
109  filter_name, filter_args);
110  return 1;
111  }
112 
113  /* create a link for each of the input pads */
114  for (i = 0; i < filter_ctx->nb_inputs; i++) {
115  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
116  link->type = filter_ctx->filter->inputs[i].type;
117  filter_ctx->inputs[i] = link;
118  }
119  for (i = 0; i < filter_ctx->nb_outputs; i++) {
120  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
121  link->type = filter_ctx->filter->outputs[i].type;
122  filter_ctx->outputs[i] = link;
123  }
124 
125  if (filter->query_formats)
126  filter->query_formats(filter_ctx);
127  else
128  ff_default_query_formats(filter_ctx);
129 
130  print_formats(filter_ctx);
131 
132  avfilter_free(filter_ctx);
133  avfilter_graph_free(&graph_ctx);
134  fflush(stdout);
135  return 0;
136 }
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:693
void av_log_set_level(int level)
Set the log level.
Definition: log.c:293
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:71
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:587
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:484
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:492
void avfilter_register_all(void)
Initialize the filter system.
Definition: allfilters.c:40
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
unsigned nb_outputs
number of output pads
Definition: avfilter.h:646
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: avcodec.h:4168
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:312
unsigned nb_inputs
number of input pads
Definition: avfilter.h:639
#define PRINT_FMTS(inout, outin, INOUT)
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:630
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:77
static void print_formats(AVFilterContext *filter_ctx)
Definition: filtfmts.c:29
#define IN(x)
Definition: vp9dsp.c:883
int avfilter_init_str(AVFilterContext *ctx, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:855
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:553
#define OUT(n)
Filter definition.
Definition: avfilter.h:464
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:635
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:460
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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-> out
An instance of a filter.
Definition: avfilter.h:627
int main(int argc, char **argv)
Definition: main.c:22
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241