Merge remote-tracking branch 'qatar/master'
[ffmpeg.git] / tools / lavfi-showfiltfmts.c
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 "libavformat/avformat.h"
22 #include "libavutil/pixdesc.h"
23 #include "libavutil/samplefmt.h"
24 #include "libavfilter/avfilter.h"
25
26 static void print_formats(AVFilterContext *filter_ctx)
27 {
28     int i, j;
29
30 #define PRINT_FMTS(inout, outin, INOUT)                                 \
31     for (i = 0; i < filter_ctx->input_count; i++) {                     \
32         if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) {   \
33             AVFilterFormats *fmts =                                     \
34                 filter_ctx->inout##puts[i]->outin##_formats;            \
35             for (j = 0; j < fmts->format_count; j++)                    \
36                 if(av_get_pix_fmt_name(fmts->formats[j]))               \
37                 printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
38                        i, filter_ctx->filter->inout##puts[i].name,      \
39                        av_get_pix_fmt_name(fmts->formats[j]));          \
40         } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
41             AVFilterFormats *fmts;                                      \
42                                                                         \
43             fmts = filter_ctx->inout##puts[i]->outin##_formats;         \
44             for (j = 0; j < fmts->format_count; j++)                    \
45                 printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
46                        i, filter_ctx->filter->inout##puts[i].name,      \
47                        av_get_sample_fmt_name(fmts->formats[j]));       \
48                                                                         \
49             fmts = filter_ctx->inout##puts[i]->outin##_chlayouts;       \
50             for (j = 0; j < fmts->format_count; j++) {                  \
51                 char buf[256];                                          \
52                 av_get_channel_layout_string(buf, sizeof(buf), -1,      \
53                                              fmts->formats[j]);         \
54                 printf(#INOUT "PUT[%d] %s: chlayout:%s\n",              \
55                        i, filter_ctx->filter->inout##puts[i].name, buf); \
56             }                                                           \
57                                                                         \
58             fmts = filter_ctx->inout##puts[i]->outin##_packing;         \
59             for (j = 0; j < fmts->format_count; j++) {                  \
60                 printf(#INOUT "PUT[%d] %s: packing:%s\n",               \
61                        i, filter_ctx->filter->inout##puts[i].name,      \
62                        fmts->formats[j] == AVFILTER_PACKED ?            \
63                                            "packed" : "planar");        \
64             }                                                           \
65         }                                                               \
66     }                                                                   \
67
68     PRINT_FMTS(in,  out, IN);
69     PRINT_FMTS(out, in,  OUT);
70 }
71
72 int main(int argc, char **argv)
73 {
74     AVFilter *filter;
75     AVFilterContext *filter_ctx;
76     const char *filter_name;
77     const char *filter_args = NULL;
78     int i;
79
80     av_log_set_level(AV_LOG_DEBUG);
81
82     if (!argv[1]) {
83         fprintf(stderr, "Missing filter name as argument\n");
84         return 1;
85     }
86
87     filter_name = argv[1];
88     if (argv[2])
89         filter_args = argv[2];
90
91     avfilter_register_all();
92
93     /* get a corresponding filter and open it */
94     if (!(filter = avfilter_get_by_name(filter_name))) {
95         fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
96         return 1;
97     }
98
99     if (avfilter_open(&filter_ctx, filter, NULL) < 0) {
100         fprintf(stderr, "Inpossible to open filter with name '%s'\n", filter_name);
101         return 1;
102     }
103     if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) {
104         fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", filter_name, filter_args);
105         return 1;
106     }
107
108     /* create a link for each of the input pads */
109     for (i = 0; i < filter_ctx->input_count; i++) {
110         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
111         link->type = filter_ctx->filter->inputs[i].type;
112         filter_ctx->inputs[i] = link;
113     }
114     for (i = 0; i < filter_ctx->output_count; i++) {
115         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
116         link->type = filter_ctx->filter->outputs[i].type;
117         filter_ctx->outputs[i] = link;
118     }
119
120     if (filter->query_formats)
121         filter->query_formats(filter_ctx);
122     else
123         avfilter_default_query_formats(filter_ctx);
124
125     print_formats(filter_ctx);
126
127     avfilter_free(filter_ctx);
128     fflush(stdout);
129     return 0;
130 }