2012-01-19 17:38:44 +01:00
|
|
|
/*
|
|
|
|
* Filter graphs to bad ASCII-art
|
|
|
|
* Copyright (c) 2012 Nicolas George
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-13 14:16:48 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-02-01 21:33:39 +01:00
|
|
|
#include "libavutil/bprint.h"
|
2012-01-19 17:38:44 +01:00
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "avfilter.h"
|
2015-08-08 10:41:31 +02:00
|
|
|
#include "internal.h"
|
2012-01-19 17:38:44 +01:00
|
|
|
|
2012-02-01 21:33:39 +01:00
|
|
|
static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
|
2012-01-19 17:38:44 +01:00
|
|
|
{
|
2021-08-26 13:35:20 +02:00
|
|
|
const char *format;
|
2021-08-31 16:03:14 +02:00
|
|
|
char layout[128];
|
2021-08-26 12:02:29 +02:00
|
|
|
AVBPrint dummy_buffer;
|
2012-01-19 17:38:44 +01:00
|
|
|
|
2021-08-26 12:02:29 +02:00
|
|
|
if (!buf) {
|
2014-04-28 04:01:50 +02:00
|
|
|
buf = &dummy_buffer;
|
2021-08-26 12:02:29 +02:00
|
|
|
av_bprint_init(buf, 0, AV_BPRINT_SIZE_COUNT_ONLY);
|
|
|
|
}
|
2012-01-19 17:38:44 +01:00
|
|
|
switch (link->type) {
|
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
|
|
|
format = av_x_if_null(av_get_pix_fmt_name(link->format), "?");
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "[%dx%d %d:%d %s]", link->w, link->h,
|
2012-01-19 17:38:44 +01:00
|
|
|
link->sample_aspect_ratio.num,
|
|
|
|
link->sample_aspect_ratio.den,
|
|
|
|
format);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
|
|
|
format = av_x_if_null(av_get_sample_fmt_name(link->format), "?");
|
2021-08-26 12:36:33 +02:00
|
|
|
av_bprintf(buf, "[%dHz %s:",
|
|
|
|
(int)link->sample_rate, format);
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_describe(&link->ch_layout, layout, sizeof(layout));
|
|
|
|
av_bprintf(buf, "%s", layout);
|
2021-08-26 12:36:33 +02:00
|
|
|
av_bprint_chars(buf, ']', 1);
|
2012-01-19 17:38:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "?");
|
2012-01-19 17:38:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-02-01 21:33:39 +01:00
|
|
|
return buf->len;
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 21:33:39 +01:00
|
|
|
static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph)
|
2012-01-19 17:38:44 +01:00
|
|
|
{
|
2012-02-01 21:33:39 +01:00
|
|
|
unsigned i, j, x, e;
|
2012-01-19 17:38:44 +01:00
|
|
|
|
2013-03-16 16:09:37 +01:00
|
|
|
for (i = 0; i < graph->nb_filters; i++) {
|
2012-01-19 17:38:44 +01:00
|
|
|
AVFilterContext *filter = graph->filters[i];
|
|
|
|
unsigned max_src_name = 0, max_dst_name = 0;
|
|
|
|
unsigned max_in_name = 0, max_out_name = 0;
|
|
|
|
unsigned max_in_fmt = 0, max_out_fmt = 0;
|
|
|
|
unsigned width, height, in_indent;
|
|
|
|
unsigned lname = strlen(filter->name);
|
|
|
|
unsigned ltype = strlen(filter->filter->name);
|
|
|
|
|
2013-08-25 19:14:17 +02:00
|
|
|
for (j = 0; j < filter->nb_inputs; j++) {
|
2012-01-19 17:38:44 +01:00
|
|
|
AVFilterLink *l = filter->inputs[j];
|
|
|
|
unsigned ln = strlen(l->src->name) + 1 + strlen(l->srcpad->name);
|
|
|
|
max_src_name = FFMAX(max_src_name, ln);
|
|
|
|
max_in_name = FFMAX(max_in_name, strlen(l->dstpad->name));
|
2012-02-01 21:33:39 +01:00
|
|
|
max_in_fmt = FFMAX(max_in_fmt, print_link_prop(NULL, l));
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
2013-08-25 19:14:17 +02:00
|
|
|
for (j = 0; j < filter->nb_outputs; j++) {
|
2012-01-19 17:38:44 +01:00
|
|
|
AVFilterLink *l = filter->outputs[j];
|
|
|
|
unsigned ln = strlen(l->dst->name) + 1 + strlen(l->dstpad->name);
|
|
|
|
max_dst_name = FFMAX(max_dst_name, ln);
|
|
|
|
max_out_name = FFMAX(max_out_name, strlen(l->srcpad->name));
|
2012-02-01 21:33:39 +01:00
|
|
|
max_out_fmt = FFMAX(max_out_fmt, print_link_prop(NULL, l));
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
|
|
|
in_indent = max_src_name + max_in_name + max_in_fmt;
|
|
|
|
in_indent += in_indent ? 4 : 0;
|
|
|
|
width = FFMAX(lname + 2, ltype + 4);
|
2013-08-25 19:14:17 +02:00
|
|
|
height = FFMAX3(2, filter->nb_inputs, filter->nb_outputs);
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprint_chars(buf, ' ', in_indent);
|
|
|
|
av_bprintf(buf, "+");
|
|
|
|
av_bprint_chars(buf, '-', width);
|
|
|
|
av_bprintf(buf, "+\n");
|
2012-01-19 17:38:44 +01:00
|
|
|
for (j = 0; j < height; j++) {
|
2013-08-25 19:14:17 +02:00
|
|
|
unsigned in_no = j - (height - filter->nb_inputs ) / 2;
|
|
|
|
unsigned out_no = j - (height - filter->nb_outputs) / 2;
|
2012-01-19 17:38:44 +01:00
|
|
|
|
|
|
|
/* Input link */
|
2013-08-25 19:14:17 +02:00
|
|
|
if (in_no < filter->nb_inputs) {
|
2012-01-19 17:38:44 +01:00
|
|
|
AVFilterLink *l = filter->inputs[in_no];
|
2012-02-01 21:33:39 +01:00
|
|
|
e = buf->len + max_src_name + 2;
|
|
|
|
av_bprintf(buf, "%s:%s", l->src->name, l->srcpad->name);
|
|
|
|
av_bprint_chars(buf, '-', e - buf->len);
|
|
|
|
e = buf->len + max_in_fmt + 2 +
|
2012-01-19 17:38:44 +01:00
|
|
|
max_in_name - strlen(l->dstpad->name);
|
2012-02-01 21:33:39 +01:00
|
|
|
print_link_prop(buf, l);
|
|
|
|
av_bprint_chars(buf, '-', e - buf->len);
|
|
|
|
av_bprintf(buf, "%s", l->dstpad->name);
|
2012-01-19 17:38:44 +01:00
|
|
|
} else {
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprint_chars(buf, ' ', in_indent);
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Filter */
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "|");
|
2012-01-19 17:38:44 +01:00
|
|
|
if (j == (height - 2) / 2) {
|
|
|
|
x = (width - lname) / 2;
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "%*s%-*s", x, "", width - x, filter->name);
|
2012-01-19 17:38:44 +01:00
|
|
|
} else if (j == (height - 2) / 2 + 1) {
|
|
|
|
x = (width - ltype - 2) / 2;
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "%*s(%s)%*s", x, "", filter->filter->name,
|
2012-01-19 17:38:44 +01:00
|
|
|
width - ltype - 2 - x, "");
|
|
|
|
} else {
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprint_chars(buf, ' ', width);
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "|");
|
2012-01-19 17:38:44 +01:00
|
|
|
|
|
|
|
/* Output link */
|
2013-08-25 19:14:17 +02:00
|
|
|
if (out_no < filter->nb_outputs) {
|
2012-01-19 17:38:44 +01:00
|
|
|
AVFilterLink *l = filter->outputs[out_no];
|
|
|
|
unsigned ln = strlen(l->dst->name) + 1 +
|
|
|
|
strlen(l->dstpad->name);
|
2012-02-01 21:33:39 +01:00
|
|
|
e = buf->len + max_out_name + 2;
|
|
|
|
av_bprintf(buf, "%s", l->srcpad->name);
|
|
|
|
av_bprint_chars(buf, '-', e - buf->len);
|
|
|
|
e = buf->len + max_out_fmt + 2 +
|
2012-01-19 17:38:44 +01:00
|
|
|
max_dst_name - ln;
|
2012-02-01 21:33:39 +01:00
|
|
|
print_link_prop(buf, l);
|
|
|
|
av_bprint_chars(buf, '-', e - buf->len);
|
|
|
|
av_bprintf(buf, "%s:%s", l->dst->name, l->dstpad->name);
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprintf(buf, "\n");
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
2012-02-01 21:33:39 +01:00
|
|
|
av_bprint_chars(buf, ' ', in_indent);
|
|
|
|
av_bprintf(buf, "+");
|
|
|
|
av_bprint_chars(buf, '-', width);
|
|
|
|
av_bprintf(buf, "+\n");
|
|
|
|
av_bprintf(buf, "\n");
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *avfilter_graph_dump(AVFilterGraph *graph, const char *options)
|
|
|
|
{
|
2012-02-01 21:33:39 +01:00
|
|
|
AVBPrint buf;
|
2019-11-21 07:58:26 +01:00
|
|
|
char *dump = NULL;
|
2012-02-01 21:33:39 +01:00
|
|
|
|
2018-06-10 10:01:35 +02:00
|
|
|
av_bprint_init(&buf, 0, AV_BPRINT_SIZE_COUNT_ONLY);
|
2012-02-01 21:33:39 +01:00
|
|
|
avfilter_graph_dump_to_buf(&buf, graph);
|
2021-08-26 13:31:06 +02:00
|
|
|
dump = av_malloc(buf.len + 1);
|
|
|
|
if (!dump)
|
|
|
|
return NULL;
|
|
|
|
av_bprint_init_for_buffer(&buf, dump, buf.len + 1);
|
2012-02-01 21:33:39 +01:00
|
|
|
avfilter_graph_dump_to_buf(&buf, graph);
|
|
|
|
return dump;
|
2012-01-19 17:38:44 +01:00
|
|
|
}
|