2 * Copyright (c) 2009 Stefano Sabatini
4 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavformat/avformat.h"
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/samplefmt.h"
26 #include "libavfilter/avfilter.h"
27 #include "libavfilter/formats.h"
29 static void print_formats(AVFilterContext *filter_ctx)
33 #define PRINT_FMTS(inout, outin, INOUT) \
34 for (i = 0; i < filter_ctx->inout##put_count; i++) { \
35 if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \
36 AVFilterFormats *fmts = \
37 filter_ctx->inout##puts[i]->outin##_formats; \
38 for (j = 0; j < fmts->format_count; j++) \
39 if(av_get_pix_fmt_name(fmts->formats[j])) \
40 printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
41 i, filter_ctx->filter->inout##puts[i].name, \
42 av_get_pix_fmt_name(fmts->formats[j])); \
43 } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
44 AVFilterFormats *fmts; \
45 AVFilterChannelLayouts *layouts; \
47 fmts = filter_ctx->inout##puts[i]->outin##_formats; \
48 for (j = 0; j < fmts->format_count; j++) \
49 printf(#INOUT "PUT[%d] %s: fmt:%s\n", \
50 i, filter_ctx->filter->inout##puts[i].name, \
51 av_get_sample_fmt_name(fmts->formats[j])); \
53 layouts = filter_ctx->inout##puts[i]->outin##_channel_layouts; \
54 for (j = 0; j < layouts->nb_channel_layouts; j++) { \
56 av_get_channel_layout_string(buf, sizeof(buf), -1, \
57 layouts->channel_layouts[j]); \
58 printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \
59 i, filter_ctx->filter->inout##puts[i].name, buf); \
64 PRINT_FMTS(in, out, IN);
65 PRINT_FMTS(out, in, OUT);
68 int main(int argc, char **argv)
71 AVFilterContext *filter_ctx;
72 const char *filter_name;
73 const char *filter_args = NULL;
76 av_log_set_level(AV_LOG_DEBUG);
79 fprintf(stderr, "Missing filter name as argument\n");
83 filter_name = argv[1];
85 filter_args = argv[2];
87 avfilter_register_all();
89 /* get a corresponding filter and open it */
90 if (!(filter = avfilter_get_by_name(filter_name))) {
91 fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
95 if (avfilter_open(&filter_ctx, filter, NULL) < 0) {
96 fprintf(stderr, "Impossible to open filter with name '%s'\n",
100 if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) {
101 fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
102 filter_name, filter_args);
106 /* create a link for each of the input pads */
107 for (i = 0; i < filter_ctx->input_count; i++) {
108 AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
109 link->type = filter_ctx->filter->inputs[i].type;
110 filter_ctx->inputs[i] = link;
112 for (i = 0; i < filter_ctx->output_count; i++) {
113 AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
114 link->type = filter_ctx->filter->outputs[i].type;
115 filter_ctx->outputs[i] = link;
118 if (filter->query_formats)
119 filter->query_formats(filter_ctx);
121 ff_default_query_formats(filter_ctx);
123 print_formats(filter_ctx);
125 avfilter_free(filter_ctx);