1 /*
2 * Copyright (c) 2008-2010 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 "config.h"
22 #if HAVE_UNISTD_H
23 #include <unistd.h> /* getopt */
24 #endif
25 #include <stdio.h>
26 #include <string.h>
27
32
33 #if !HAVE_GETOPT
35 #endif
36
38 {
39 printf("Convert a libavfilter graph to a dot file.\n");
40 printf("Usage: graph2dot [OPTIONS]\n");
41 printf("\n"
42 "Options:\n"
43 "-i INFILE set INFILE as input file, stdin if omitted\n"
44 "-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
45 "-h print this help\n");
46 }
47
51 };
52
54 {
55 int i, j;
56
57 fprintf(outfile, "digraph G {\n");
58 fprintf(outfile, "node [shape=box]\n");
59 fprintf(outfile, "rankdir=LR\n");
60
62 char filter_ctx_label[128];
64
65 snprintf(filter_ctx_label,
sizeof(filter_ctx_label),
"%s\\n(%s)",
68
71 if (link) {
72 char dst_filter_ctx_label[128];
74
75 snprintf(dst_filter_ctx_label,
sizeof(dst_filter_ctx_label),
76 "%s\\n(%s)",
79
80 fprintf(outfile, "\"%s\" -> \"%s\" [ label= \"inpad:%s -> outpad:%s\\n",
81 filter_ctx_label, dst_filter_ctx_label,
83
86 fprintf(outfile,
87 "fmt:%s w:%d h:%d tb:%d/%d",
95 fprintf(outfile,
96 "fmt:%s sr:%d cl:%s tb:%d/%d",
100 }
101 fprintf(outfile, "\" ];\n");
102 }
103 }
104 }
105 fprintf(outfile, "}\n");
106 }
107
108 int main(
int argc,
char **argv)
109 {
110 const char *outfilename = NULL;
111 const char *infilename = NULL;
113 FILE *infile = NULL;
114 char *graph_string = NULL;
117
119
120 while ((c =
getopt(argc, argv,
"hi:o:")) != -1) {
121 switch (c) {
122 case 'h':
124 return 0;
125 case 'i':
127 break;
128 case 'o':
130 break;
131 case '?':
132 return 1;
133 }
134 }
135
136 if (!infilename || !strcmp(infilename, "-"))
137 infilename = "/dev/stdin";
138 infile = fopen(infilename, "r");
139 if (!infile) {
140 fprintf(stderr, "Failed to open input file '%s': %s\n",
141 infilename, strerror(errno));
142 return 1;
143 }
144
145 if (!outfilename || !strcmp(outfilename, "-"))
146 outfilename = "/dev/stdout";
147 outfile = fopen(outfilename, "w");
148 if (!outfile) {
149 fprintf(stderr, "Failed to open output file '%s': %s\n",
150 outfilename, strerror(errno));
151 return 1;
152 }
153
154 /* read from infile and put it in a buffer */
155 {
156 unsigned int count = 0;
157 struct line *
line, *last_line, *first_line;
158 char *p;
159 last_line = first_line =
av_malloc(
sizeof(
struct line));
160
161 while (fgets(last_line->
data,
sizeof(last_line->
data), infile)) {
162 struct line *new_line =
av_malloc(
sizeof(
struct line));
163 count += strlen(last_line->
data);
164 last_line->
next = new_line;
165 last_line = new_line;
166 }
167 last_line->
next = NULL;
168
170 p = graph_string;
171 for (line = first_line; line->
next; line = line->
next) {
172 unsigned int l = strlen(line->
data);
173 memcpy(p, line->
data, l);
174 p += l;
175 }
176 *p = '0円';
177 }
178
180
182 fprintf(stderr, "Failed to parse the graph description\n");
183 return 1;
184 }
185
187 return 1;
188
190 fflush(outfile);
191
192 return 0;
193 }