diff --git a/tools/graph2dot.c b/tools/graph2dot.c
index 23c7331dc3127de8640ff97aeb74de9bdef77928..21d0795e8818478c59609518afd350c99f8e1fa8 100644
--- a/tools/graph2dot.c
+++ b/tools/graph2dot.c
@@ -79,7 +79,8 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph)
 
                 fprintf(outfile, "\"%s\" -> \"%s\" [ label= \"inpad:%s -> outpad:%s\\n",
                         filter_ctx_label, dst_filter_ctx_label,
-                        link->srcpad->name, link->dstpad->name);
+                        avfilter_pad_get_name(link->srcpad, 0),
+                        avfilter_pad_get_name(link->dstpad, 0));
 
                 if (link->type == AVMEDIA_TYPE_VIDEO) {
                     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);