• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
22 
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/samplefmt.h"
27 
28 #define FF_INTERNAL_FIELDS 1
29 #include "libavfilter/framequeue.h"
30 
31 #include "libavfilter/avfilter.h"
32 #include "libavfilter/formats.h"
33 #include "libavfilter/internal.h"
34 
print_formats_internal(AVFilterLink ** links,const AVFilterPad * pads,unsigned nb,size_t fmts_cfg_offset,const char * inout_string)35 static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads,
36                                    unsigned nb, size_t fmts_cfg_offset,
37                                    const char *inout_string)
38 {
39     for (unsigned i = 0; i < nb; i++) {
40         const AVFilterLink *const link = links[i];
41         const AVFilterFormatsConfig *const cfg = (AVFilterFormatsConfig*)((const char*)link + fmts_cfg_offset);
42         const char *pad_name = avfilter_pad_get_name(pads, i);
43 
44         if (link->type == AVMEDIA_TYPE_VIDEO) {
45             const AVFilterFormats *const fmts = cfg->formats;
46             for (unsigned j = 0; fmts && j < fmts->nb_formats; j++) {
47                 printf("%s[%u] %s: fmt:%s\n",
48                         inout_string, i, pad_name,
49                         av_get_pix_fmt_name(fmts->formats[j]));
50             }
51         } else if (link->type == AVMEDIA_TYPE_AUDIO) {
52             const AVFilterFormats *const fmts = cfg->formats;
53             const AVFilterChannelLayouts *const layouts = cfg->channel_layouts;
54 
55             for (unsigned j = 0; fmts && j < fmts->nb_formats; j++)
56                 printf("%s[%u] %s: fmt:%s\n",
57                        inout_string, i, pad_name,
58                        av_get_sample_fmt_name(fmts->formats[j]));
59 
60             for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) {
61                 char buf[256];
62                 av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf));
63                 printf("%s[%u] %s: chlayout:%s\n",
64                        inout_string, i, pad_name, buf);
65             }
66         }
67     }
68 }
69 
print_formats(AVFilterContext * filter_ctx)70 static void print_formats(AVFilterContext *filter_ctx)
71 {
72     print_formats_internal(filter_ctx->inputs, filter_ctx->input_pads,
73                            filter_ctx->nb_inputs,
74                            offsetof(AVFilterLink, outcfg), "INPUT");
75     print_formats_internal(filter_ctx->outputs, filter_ctx->output_pads,
76                            filter_ctx->nb_outputs,
77                            offsetof(AVFilterLink, incfg), "OUTPUT");
78 }
79 
main(int argc,char ** argv)80 int main(int argc, char **argv)
81 {
82     const AVFilter *filter;
83     AVFilterContext *filter_ctx;
84     AVFilterGraph *graph_ctx;
85     const char *filter_name;
86     const char *filter_args = NULL;
87     int i;
88     int ret = 0;
89 
90     av_log_set_level(AV_LOG_DEBUG);
91 
92     if (argc < 2) {
93         fprintf(stderr, "Missing filter name as argument\n");
94         return 1;
95     }
96 
97     filter_name = argv[1];
98     if (argc > 2)
99         filter_args = argv[2];
100 
101     /* allocate graph */
102     graph_ctx = avfilter_graph_alloc();
103     if (!graph_ctx)
104         return 1;
105 
106     /* get a corresponding filter and open it */
107     if (!(filter = avfilter_get_by_name(filter_name))) {
108         fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
109         return 1;
110     }
111 
112     /* open filter and add it to the graph */
113     if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
114         fprintf(stderr, "Impossible to open filter with name '%s'\n",
115                 filter_name);
116         return 1;
117     }
118     if (avfilter_init_str(filter_ctx, filter_args) < 0) {
119         fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
120                 filter_name, filter_args);
121         return 1;
122     }
123 
124     /* create a link for each of the input pads */
125     for (i = 0; i < filter_ctx->nb_inputs; i++) {
126         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
127         if (!link) {
128             fprintf(stderr, "Unable to allocate memory for filter input link\n");
129             ret = 1;
130             goto fail;
131         }
132         link->type = avfilter_pad_get_type(filter_ctx->input_pads, i);
133         filter_ctx->inputs[i] = link;
134     }
135     for (i = 0; i < filter_ctx->nb_outputs; i++) {
136         AVFilterLink *link = av_mallocz(sizeof(AVFilterLink));
137         if (!link) {
138             fprintf(stderr, "Unable to allocate memory for filter output link\n");
139             ret = 1;
140             goto fail;
141         }
142         link->type = avfilter_pad_get_type(filter_ctx->output_pads, i);
143         filter_ctx->outputs[i] = link;
144     }
145 
146     if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
147         ret = filter->formats.query_func(filter_ctx);
148     else
149         ret = ff_default_query_formats(filter_ctx);
150 
151     print_formats(filter_ctx);
152 
153 fail:
154     avfilter_free(filter_ctx);
155     avfilter_graph_free(&graph_ctx);
156     fflush(stdout);
157     return ret;
158 }
159