Libav
filtfmts.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 <stdio.h>
22 
23 #include "libavformat/avformat.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavfilter/avfilter.h"
26 #include "libavfilter/formats.h"
27 
28 int main(int argc, char **argv)
29 {
31  AVFilterContext *filter_ctx;
32  AVFilterGraph *graph_ctx;
33  const char *filter_name;
34  const char *filter_args = NULL;
35  int i, j;
36 
38 
39  if (!argv[1]) {
40  fprintf(stderr, "Missing filter name as argument\n");
41  return 1;
42  }
43 
44  filter_name = argv[1];
45  if (argv[2])
46  filter_args = argv[2];
47 
48  /* allocate graph */
49  graph_ctx = avfilter_graph_alloc();
50  if (!graph_ctx)
51  return 1;
52 
54 
55  /* get a corresponding filter and open it */
56  if (!(filter = avfilter_get_by_name(filter_name))) {
57  fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
58  return 1;
59  }
60 
61  /* open filter and add it to the graph */
62  if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
63  fprintf(stderr, "Impossible to open filter with name '%s'\n",
64  filter_name);
65  return 1;
66  }
67  if (avfilter_init_str(filter_ctx, filter_args) < 0) {
68  fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
69  filter_name, filter_args);
70  return 1;
71  }
72 
73  /* create a link for each of the input pads */
74  for (i = 0; i < filter_ctx->nb_inputs; i++) {
75  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
76  link->type = filter_ctx->filter->inputs[i].type;
77  filter_ctx->inputs[i] = link;
78  }
79  for (i = 0; i < filter_ctx->nb_outputs; i++) {
80  AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
81  link->type = filter_ctx->filter->outputs[i].type;
82  filter_ctx->outputs[i] = link;
83  }
84 
85  if (filter->query_formats)
86  filter->query_formats(filter_ctx);
87  else
88  ff_default_query_formats(filter_ctx);
89 
90  /* print the supported formats in input */
91  for (i = 0; i < filter_ctx->nb_inputs; i++) {
92  AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
93  for (j = 0; j < fmts->nb_formats; j++)
94  printf("INPUT[%d] %s: %s\n",
95  i, filter_ctx->filter->inputs[i].name,
96  av_get_pix_fmt_name(fmts->formats[j]));
97  }
98 
99  /* print the supported formats in output */
100  for (i = 0; i < filter_ctx->nb_outputs; i++) {
101  AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
102  for (j = 0; j < fmts->nb_formats; j++)
103  printf("OUTPUT[%d] %s: %s\n",
104  i, filter_ctx->filter->outputs[i].name,
105  av_get_pix_fmt_name(fmts->formats[j]));
106  }
107 
108  avfilter_free(filter_ctx);
109  avfilter_graph_free(&graph_ctx);
110  fflush(stdout);
111  return 0;
112 }
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:491
static const char * filter_name(void *p)
Definition: avfilter.c:330
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:71
Main libavfilter public API header.
void av_log_set_level(int level)
Set the log level.
Definition: log.c:170
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:47
int(* query_formats)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: avfilter.h:544
const char * name
Pad name.
Definition: internal.h:42
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:571
void avfilter_register_all(void)
Initialize the filter system.
Definition: allfilters.c:39
unsigned nb_outputs
number of output pads
Definition: avfilter.h:582
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: avfilter.c:278
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
Definition: mpegaudioenc.c:307
unsigned nb_inputs
number of input pads
Definition: avfilter.h:575
unsigned nb_formats
number of formats
Definition: formats.h:65
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:596
const AVFilterPad * inputs
List of inputs, terminated by a zeroed element.
Definition: avfilter.h:441
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:381
NULL
Definition: eval.c:55
Filter definition.
Definition: avfilter.h:421
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:578
Main libavformat public API header.
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:28
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:563
const AVFilterPad * outputs
List of outputs, terminated by a zeroed element.
Definition: avfilter.h:449
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:1449
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:205
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:566
int * formats
list of media formats
Definition: formats.h:66