mp3: Properly use AVCodecContext API
[platform/upstream/libav.git] / libavfilter / filtfmts.c
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 "libavutil/mem.h"
24 #include "libavutil/pixdesc.h"
25
26 #include "libavfilter/avfilter.h"
27 #include "libavfilter/formats.h"
28
29 int main(int argc, char **argv)
30 {
31     AVFilter *filter;
32     AVFilterContext *filter_ctx;
33     AVFilterGraph *graph_ctx;
34     const char *filter_name;
35     const char *filter_args = NULL;
36     int i, j;
37
38     av_log_set_level(AV_LOG_DEBUG);
39
40     if (!argv[1]) {
41         fprintf(stderr, "Missing filter name as argument\n");
42         return 1;
43     }
44
45     filter_name = argv[1];
46     if (argv[2])
47         filter_args = argv[2];
48
49     /* allocate graph */
50     graph_ctx = avfilter_graph_alloc();
51     if (!graph_ctx)
52         return 1;
53
54     avfilter_register_all();
55
56     /* get a corresponding filter and open it */
57     if (!(filter = avfilter_get_by_name(filter_name))) {
58         fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
59         return 1;
60     }
61
62     /* open filter and add it to the graph */
63     if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
64         fprintf(stderr, "Impossible to open filter with name '%s'\n",
65                 filter_name);
66         return 1;
67     }
68     if (avfilter_init_str(filter_ctx, filter_args) < 0) {
69         fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
70                 filter_name, filter_args);
71         return 1;
72     }
73
74     /* create a link for each of the input pads */
75     for (i = 0; i < filter_ctx->nb_inputs; i++) {
76         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
77         link->type = avfilter_pad_get_type(filter_ctx->filter->inputs, i);
78         filter_ctx->inputs[i] = link;
79     }
80     for (i = 0; i < filter_ctx->nb_outputs; i++) {
81         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
82         link->type = avfilter_pad_get_type(filter_ctx->filter->outputs, i);
83         filter_ctx->outputs[i] = link;
84     }
85
86     if (filter->query_formats)
87         filter->query_formats(filter_ctx);
88     else
89         ff_default_query_formats(filter_ctx);
90
91     /* print the supported formats in input */
92     for (i = 0; i < filter_ctx->nb_inputs; i++) {
93         AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
94         for (j = 0; j < fmts->nb_formats; j++)
95             printf("INPUT[%d] %s: %s\n",
96                    i, avfilter_pad_get_name(filter_ctx->filter->inputs, i),
97                    av_get_pix_fmt_name(fmts->formats[j]));
98     }
99
100     /* print the supported formats in output */
101     for (i = 0; i < filter_ctx->nb_outputs; i++) {
102         AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
103         for (j = 0; j < fmts->nb_formats; j++)
104             printf("OUTPUT[%d] %s: %s\n",
105                    i, avfilter_pad_get_name(filter_ctx->filter->outputs, i),
106                    av_get_pix_fmt_name(fmts->formats[j]));
107     }
108
109     avfilter_free(filter_ctx);
110     avfilter_graph_free(&graph_ctx);
111     fflush(stdout);
112     return 0;
113 }