FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/samplefmt.h"
27 
28 #define FF_INTERNAL_FIELDS 1
29 #include "libavfilter/framequeue.h"
30 
31 #include "libavfilter/avfilter.h"
32 #include "libavfilter/formats.h"
33 #include "libavfilter/internal.h"
34 
36 {
37  int i, j;
38 
39 #define PRINT_FMTS(inout, outin, INOUT) \
40  for (i = 0; i < filter_ctx->nb_##inout##puts; i++) { \
41  if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
42  AVFilterFormats *fmts = \
43  filter_ctx->inout##puts[i]->outin##_formats; \
44  for (j = 0; j < fmts->nb_formats; j++) \
45  if(av_get_pix_fmt_name(fmts->formats[j])) \
46  printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
47  i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), \
48  av_get_pix_fmt_name(fmts->formats[j])); \
49  } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
50  AVFilterFormats *fmts; \
51  AVFilterChannelLayouts *layouts; \
52  \
53  fmts = filter_ctx->inout##puts[i]->outin##_formats; \
54  for (j = 0; j < fmts->nb_formats; j++) \
55  printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
56  i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), \
57  av_get_sample_fmt_name(fmts->formats[j])); \
58  \
59  layouts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
60  for (j = 0; j < layouts->nb_channel_layouts; j++) { \
61  char buf[256]; \
62  av_get_channel_layout_string(buf, sizeof(buf), -1, \
63  layouts->channel_layouts[j]); \
64  printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
65  i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), buf); \
66  } \
67  } \
68  } \
69 
70  PRINT_FMTS(in, out, IN);
71  PRINT_FMTS(out, in, OUT);
72 }
73 
74 int main(int argc, char **argv)
75 {
76  const AVFilter *filter;
78  AVFilterGraph *graph_ctx;
79  const char *filter_name;
80  const char *filter_args = NULL;
81  int i;
82  int ret = 0;
83 
85 
86  if (argc < 2) {
87  fprintf(stderr, "Missing filter name as argument\n");
88  return 1;
89  }
90 
91  filter_name = argv[1];
92  if (argc > 2)
93  filter_args = argv[2];
94 
95  /* allocate graph */
96  graph_ctx = avfilter_graph_alloc();
97  if (!graph_ctx)
98  return 1;
99 
100  /* get a corresponding filter and open it */
101  if (!(filter = avfilter_get_by_name(filter_name))) {
102  fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
103  return 1;
104  }
105 
106  /* open filter and add it to the graph */
107  if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
108  fprintf(stderr, "Impossible to open filter with name '%s'\n",
109  filter_name);
110  return 1;
111  }
112  if (avfilter_init_str(filter_ctx, filter_args) < 0) {
113  fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
114  filter_name, filter_args);
115  return 1;
116  }
117 
118  /* create a link for each of the input pads */
119  for (i = 0; i < filter_ctx->nb_inputs; i++) {
120  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
121  if (!link) {
122  fprintf(stderr, "Unable to allocate memory for filter input link\n");
123  ret = 1;
124  goto fail;
125  }
126  link->type = avfilter_pad_get_type(filter_ctx->input_pads, i);
127  filter_ctx->inputs[i] = link;
128  }
129  for (i = 0; i < filter_ctx->nb_outputs; i++) {
130  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
131  if (!link) {
132  fprintf(stderr, "Unable to allocate memory for filter output link\n");
133  ret = 1;
134  goto fail;
135  }
136  link->type = avfilter_pad_get_type(filter_ctx->output_pads, i);
137  filter_ctx->outputs[i] = link;
138  }
139 
140  if (filter->query_formats)
141  ret = filter->query_formats(filter_ctx);
142  else
143  ret = ff_default_query_formats(filter_ctx);
144 
145  print_formats(filter_ctx);
146 
147 fail:
148  avfilter_free(filter_ctx);
149  avfilter_graph_free(&graph_ctx);
150  fflush(stdout);
151  return ret;
152 }
#define NULL
Definition: coverity.c:32
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:760
#define IN(x)
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:83
Main libavfilter public API header.
Memory handling functions.
void av_log_set_level(int level)
Set the log level.
Definition: log.c:385
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:1039
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:282
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:349
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhd.c:153
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
unsigned nb_outputs
number of output pads
Definition: avfilter.h:351
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static FilteringContext * filter_ctx
Definition: transcoding.c:45
#define fail()
Definition: checkasm.h:117
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:466
audio channel layout utility functions
unsigned nb_inputs
number of input pads
Definition: avfilter.h:347
#define PRINT_FMTS(inout, outin, INOUT)
static void print_formats(AVFilterContext *filter_ctx)
Definition: filtfmts.c:35
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:924
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:597
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
Filter definition.
Definition: avfilter.h:144
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
int main(int argc, char **argv)
Definition: filtfmts.c:74
An instance of a filter.
Definition: avfilter.h:338
FILE * out
Definition: movenc.c:54
internal API functions