From 1160c79015273ee850eb0a350d77480baef2fa52 Mon Sep 17 00:00:00 2001
From: Christian Vogel <vogelchr@vogel.cx>
Date: Mon, 9 Apr 2012 21:03:01 +0200
Subject: [PATCH] filter ctrl chars on dump

---
 libavformat/utils.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index ebf34de..48d52b6 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3623,6 +3623,18 @@ static void print_fps(double d, const char *postfix){
     else                  av_log(NULL, AV_LOG_INFO, ", %1.0fk %s", d/1000, postfix);
 }
 
+/* sometimes control-characters are hidden in files' metadata, make sure
+ * they are not dumped to stdout, messing up the console */
+
+static void dump_md_clean(char *s,int len){
+	while(len){
+		if(*s > 0 && *s < 32)
+			*s='?';
+		len--;
+		s++;
+	}
+}
+
 static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
 {
     if(m && !(m->count == 1 && av_dict_get(m, "language", NULL, 0))){
@@ -3637,6 +3649,7 @@ static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
                     char tmp[256];
                     size_t len = strcspn(p, "\xd\xa");
                     av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1));
+		    dump_md_clean(tmp,len);
                     av_log(ctx, AV_LOG_INFO, "%s", tmp);
                     p += len;
                     if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " ");
-- 
1.7.0.4

