examples: filter_audio: Add missing mem.h header for av_freep()
[libav.git] / libavfilter / filtfmts.c
CommitLineData
e34d5db5
SS
1/*
2 * Copyright (c) 2009 Stefano Sabatini
3 *
2912e87a 4 * This file is part of Libav.
e34d5db5 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
e34d5db5
SS
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 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
e34d5db5
SS
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
e34d5db5
SS
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
7c29377b
MR
21#include <stdio.h>
22
e34d5db5
SS
23#include "libavutil/pixdesc.h"
24#include "libavfilter/avfilter.h"
43c7a01e 25#include "libavfilter/formats.h"
e34d5db5
SS
26
27int main(int argc, char **argv)
28{
29 AVFilter *filter;
30 AVFilterContext *filter_ctx;
6756d98c 31 AVFilterGraph *graph_ctx;
e34d5db5
SS
32 const char *filter_name;
33 const char *filter_args = NULL;
34 int i, j;
35
36 av_log_set_level(AV_LOG_DEBUG);
37
38 if (!argv[1]) {
39 fprintf(stderr, "Missing filter name as argument\n");
40 return 1;
41 }
42
43 filter_name = argv[1];
44 if (argv[2])
45 filter_args = argv[2];
46
6756d98c
VG
47 /* allocate graph */
48 graph_ctx = avfilter_graph_alloc();
49 if (!graph_ctx)
50 return 1;
51
e34d5db5
SS
52 avfilter_register_all();
53
54 /* get a corresponding filter and open it */
55 if (!(filter = avfilter_get_by_name(filter_name))) {
56 fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
57 return 1;
58 }
59
6756d98c
VG
60 /* open filter and add it to the graph */
61 if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
ffae713a 62 fprintf(stderr, "Impossible to open filter with name '%s'\n",
4e81b5f5 63 filter_name);
e34d5db5
SS
64 return 1;
65 }
48a5adab 66 if (avfilter_init_str(filter_ctx, filter_args) < 0) {
4e81b5f5
DB
67 fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
68 filter_name, filter_args);
e34d5db5
SS
69 return 1;
70 }
71
72 /* create a link for each of the input pads */
e7399695 73 for (i = 0; i < filter_ctx->nb_inputs; i++) {
c61f84bf
MR
74 AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
75 link->type = filter_ctx->filter->inputs[i].type;
e34d5db5
SS
76 filter_ctx->inputs[i] = link;
77 }
e7399695 78 for (i = 0; i < filter_ctx->nb_outputs; i++) {
c61f84bf 79 AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
a8542e43 80 link->type = filter_ctx->filter->outputs[i].type;
e34d5db5
SS
81 filter_ctx->outputs[i] = link;
82 }
83
84 if (filter->query_formats)
85 filter->query_formats(filter_ctx);
86 else
43c7a01e 87 ff_default_query_formats(filter_ctx);
e34d5db5
SS
88
89 /* print the supported formats in input */
e7399695 90 for (i = 0; i < filter_ctx->nb_inputs; i++) {
e34d5db5 91 AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats;
b01f6041 92 for (j = 0; j < fmts->nb_formats; j++)
27971664
MR
93 printf("INPUT[%d] %s: %s\n",
94 i, filter_ctx->filter->inputs[i].name,
59ee9f78 95 av_get_pix_fmt_name(fmts->formats[j]));
e34d5db5
SS
96 }
97
98 /* print the supported formats in output */
e7399695 99 for (i = 0; i < filter_ctx->nb_outputs; i++) {
e34d5db5 100 AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats;
b01f6041 101 for (j = 0; j < fmts->nb_formats; j++)
27971664
MR
102 printf("OUTPUT[%d] %s: %s\n",
103 i, filter_ctx->filter->outputs[i].name,
59ee9f78 104 av_get_pix_fmt_name(fmts->formats[j]));
e34d5db5
SS
105 }
106
24de0edb 107 avfilter_free(filter_ctx);
6756d98c 108 avfilter_graph_free(&graph_ctx);
e34d5db5
SS
109 fflush(stdout);
110 return 0;
111}