I'm redirecting avconv output to a file and \r's coming from avconv's stats printing bug me. Attached are two simple patches one that solve my problem in libavutil and the other in avconv.
The avconv patch makes -stats int so it is basically not backwards compatible so I prefer the general solution in libavutil. Comments, flames, suggestions? -- Georgi Chorbadzhiyski http://georgi.unixsol.org/
From 44862b7d3873abfb21e06ab15741824e0f5a2a04 Mon Sep 17 00:00:00 2001 From: Georgi Chorbadzhiyski <[email protected]> Date: Thu, 1 Dec 2011 01:44:27 +0200 Subject: [PATCH 1/2] libavutil: If the output is not terminal replace \r with \n in av_log(). When redirecting output to file \r symbols are not doing any good so replace them with \n. --- libavutil/log.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/libavutil/log.c b/libavutil/log.c index 4d2b539..80735b4 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -120,6 +120,17 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) fprintf(stderr, " Last message repeated %d times\n", count); count=0; } + +#if HAVE_ISATTY + if (is_atty == -1) { + int i, len = strlen(line); + for (i = 0; i < len; i++) { + if (line[i] == '\r') + line[i] = '\n'; + } + } +#endif + colored_fputs(av_clip(level>>3, 0, 6), line); av_strlcpy(prev, line, sizeof line); } -- 1.7.5.1
From cafaa696c8c216031e84711e001e6ac5fb0199a4 Mon Sep 17 00:00:00 2001 From: Georgi Chorbadzhiyski <[email protected]> Date: Thu, 1 Dec 2011 01:48:10 +0200 Subject: [PATCH 2/2] avconv: Allow stats to be printed as new lines. This patch turns -stats parameter into integer that currently have 3 values. 0 - disable stats, 1 - print stats on single line, 2 - print each stat on new line. --- avconv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avconv.c b/avconv.c index d6045b7..531972f 100644 --- a/avconv.c +++ b/avconv.c @@ -1429,7 +1429,7 @@ static void print_report(OutputFile *output_files, snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", nb_frames_dup, nb_frames_drop); - av_log(NULL, AV_LOG_INFO, "%s \r", buf); + av_log(NULL, AV_LOG_INFO, "%s%s", buf, print_stats == 1 ? " \r" : "\n"); fflush(stderr); @@ -4185,7 +4185,7 @@ static const OptionDef options[] = { #if CONFIG_AVFILTER { "filter", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(filters)}, "set stream filterchain", "filter_list" }, #endif - { "stats", OPT_BOOL, {&print_stats}, "print progress report during encoding", }, + { "stats", HAS_ARG | OPT_INT, {&print_stats}, "print progress report during encoding", }, { "attach", HAS_ARG | OPT_FUNC2, {(void*)opt_attach}, "add an attachment to the output file", "filename" }, { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(dump_attachment)}, "extract an attachment into a file", "filename" }, -- 1.7.5.1
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
