lavfi-showfiltfmts.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavformat/avformat.h"
22 #include "libavutil/pixdesc.h"
23 #include "libavfilter/avfilter.h"
24 
25 int main(int argc, char **argv)
26 {
28  AVFilterContext *filter_ctx;
29  const char *filter_name;
30  const char *filter_args = NULL;
31  int i, j;
32 
34 
35  if (!argv[1]) {
36  fprintf(stderr, "Missing filter name as argument\n");
37  return 1;
38  }
39 
40  filter_name = argv[1];
41  if (argv[2])
42  filter_args = argv[2];
43 
45 
46  /* get a corresponding filter and open it */
47  if (!(filter = avfilter_get_by_name(filter_name))) {
48  fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
49  return 1;
50  }
51 
52  if (avfilter_open(&filter_ctx, filter, NULL) < 0) {
53  fprintf(stderr, "Inpossible to open filter with name '%s'\n", filter_name);
54  return 1;
55  }
56  if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) {
57  fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", filter_name, filter_args);
58  return 1;
59  }
60 
61  /* create a link for each of the input pads */
62  for (i = 0; i < filter_ctx->input_count; i++) {
63  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
64  link->type = filter_ctx->filter->inputs[i].type;
65  filter_ctx->inputs[i] = link;
66  }
67  for (i = 0; i < filter_ctx->output_count; i++) {
68  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
69  link->type = filter_ctx->filter->outputs[i].type;
70  filter_ctx->outputs[i] = link;
71  }
72 
73  if (filter->query_formats)
74  filter->query_formats(filter_ctx);
75  else
77 
78  /* print the supported formats in input */
79  for (i = 0; i < filter_ctx->input_count; i++) {
80  AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
81  for (j = 0; j < fmts->format_count; j++)
82  printf("INPUT[%d] %s: %s\n",
83  i, filter_ctx->filter->inputs[i].name,
85  }
86 
87  /* print the supported formats in output */
88  for (i = 0; i < filter_ctx->output_count; i++) {
89  AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
90  for (j = 0; j < fmts->format_count; j++)
91  printf("OUTPUT[%d] %s: %s\n",
92  i, filter_ctx->filter->outputs[i].name,
94  }
95 
96  avfilter_free(filter_ctx);
97  fflush(stdout);
98  return 0;
99 }
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:154
void avfilter_register_all(void)
Initialize the filter system.
Definition: allfilters.c:29
static const char * filter_name(void *p)
Definition: avfilter.c:569
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:640
enum AVMediaType type
AVFilterPad type.
Definition: avfilter.h:324
int(* query_formats)(AVFilterContext *)
Queries formats supported by the filter and its pads, and sets the in_formats for links connected to ...
Definition: avfilter.h:525
const char * name
Pad name.
Definition: avfilter.h:318
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:547
unsigned input_count
number of input pads
Definition: avfilter.h:545
const char * name
Definition: pixdesc.h:56
int avfilter_default_query_formats(AVFilterContext *ctx)
Default handler for query_formats()
Definition: defaults.c:258
int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
Initialize a filter.
Definition: avfilter.c:676
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:530
int main(int argc, char **argv)
void av_log_set_level(int level)
Definition: log.c:162
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
Definition: pixdesc.c:119
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:311
unsigned output_count
number of output pads
Definition: avfilter.h:549
int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
Create a filter instance.
Definition: avfilter.c:582
const AVFilterPad * inputs
NULL terminated list of inputs. NULL if none.
Definition: avfilter.h:527
NULL
Definition: eval.c:50
Filter definition.
Definition: avfilter.h:497
#define printf
Definition: internal.h:151
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:551
Main libavformat public API header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:125
AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:541
A list of supported formats for one end of a filter link.
Definition: avfilter.h:220
An instance of a filter.
Definition: avfilter.h:538
#define fprintf
Definition: internal.h:153
const AVFilterPad * outputs
NULL terminated list of outputs. NULL if none.
Definition: avfilter.h:528
unsigned format_count
number of formats
Definition: avfilter.h:221
int * formats
list of media formats
Definition: avfilter.h:222