OSDN Git Service

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