diff mbox series

[FFmpeg-devel] fftools/cmdutils: add an option to append to the report file

Message ID 903e60ec-f7a7-5ab9-8775-f800b76f6724@gmail.com
State New
Headers show
Series [FFmpeg-devel] fftools/cmdutils: add an option to append to the report file | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
andriy/configure_ppc warning Failed to apply patch

Commit Message

Dan Zwell Feb. 1, 2022, 1:02 p.m. UTC
There are times when we want ffmpeg to log, but we don't want it to
overwrite the log file. In addition to the use case described in the
ticket, a third party tool that invokes ffmpeg may write additional
information to the log file, such as why the encoding options were
chosen.

I made the error checking nonfatal for future compatibility, because
this feature is aimed at scripts and ffmpeg frontends.

This implements:
https://trac.ffmpeg.org/ticket/3059

Note: unknown keys are ignored, so adding a new "append" key does not
break backward compatibility.

Signed-off-by: Dan Zwell <devel@zwell.net>
---
  doc/fftools-common-opts.texi |  3 +++
  fftools/cmdutils.c           | 13 ++++++++++++-
  2 files changed, 15 insertions(+), 1 deletion(-)

                  exit_program(1);
              }
              envlevel = 1;
+        } else if (!strcmp(key, "append")) {
+            char *tail;
+            append = strtol(val, &tail, 10);
+            if (*val == '\0' || *tail || (append != 0 && append != 1)) {
+                av_log(NULL, AV_LOG_ERROR, "Invalid append value '%s' 
(should be 0 or 1)\n", val);
+                append = 0;
+            }
          } else {
              av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in 
FFREPORT\n", key);
          }
@@ -1032,7 +1040,10 @@ static int init_report(const char *env)
      if (!envlevel)
          report_file_level = FFMAX(report_file_level, prog_loglevel);
  -    report_file = fopen(filename.str, "w");
+    if (append)
+        report_file = fopen(filename.str, "a");
+    else
+        report_file = fopen(filename.str, "w");
      if (!report_file) {
          int ret = AVERROR(errno);
          av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
diff mbox series

Patch

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index d9145704d6..a9a8eda417 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -270,6 +270,9 @@  of the program, @code{%t} is expanded to a 
timestamp, @code{%%} is expanded
  to a plain @code{%}
  @item level
  set the log verbosity level using a numerical value (see 
@code{-loglevel}).
+@item append
+@code{append=1} tells ffmpeg to append to a report file if it exists 
instead of
+overwriting it. @code{append=0} is the default
  @end table
   For example, to output a report to a file named @file{ffreport.log}
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15eef..08aec489cb 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -983,6 +983,7 @@  static int init_report(const char *env)
      time_t now;
      struct tm *tm;
      AVBPrint filename;
+    int append = 0;
       if (report_file) /* already opened */
          return 0;
@@ -1012,6 +1013,13 @@  static int init_report(const char *env)