Patchwork Add option -n to exit if output file exists.

login
register
mail settings
Submitter Carl Eugen Hoyos
Date Nov. 24, 2011, 8:45 p.m.
Message ID <20111124204522.A5B4B144C4E@albiero.videolan.org>
Download mbox | patch
Permalink /patch/12338/
State New
Headers show

Comments

Carl Eugen Hoyos - Nov. 24, 2011, 8:45 p.m.
ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos@ag.or.at> | Thu Nov 24 21:42:42 2011 +0100| [0a4f02117b67c135a27e3490aea1631ad9f4312f] | committer: Carl Eugen Hoyos

Add option -n to exit if output file exists.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0a4f02117b67c135a27e3490aea1631ad9f4312f
---

 avconv.c        |    6 ++++--
 doc/avconv.texi |    3 +++
 doc/ffmpeg.texi |    3 +++
 ffmpeg.c        |    6 ++++--
 4 files changed, 14 insertions(+), 4 deletions(-)

Patch

diff --git a/avconv.c b/avconv.c
index 4cf2e2f..4620b2b 100644
--- a/avconv.c
+++ b/avconv.c
@@ -119,6 +119,7 @@  static int intra_dc_precision = 8;
 static int qp_hist = 0;
 
 static int file_overwrite = 0;
+static int no_file_overwrite = 0;
 static int do_benchmark = 0;
 static int do_hex_dump = 0;
 static int do_pkt_dump = 0;
@@ -3016,11 +3017,11 @@  static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
 
 static void assert_file_overwrite(const char *filename)
 {
-    if (!file_overwrite &&
+    if ((!file_overwrite || no_file_overwrite) &&
         (strchr(filename, ':') == NULL || filename[1] == ':' ||
          av_strstart(filename, "file:", NULL))) {
         if (avio_check(filename, 0) == 0) {
-            if (!using_stdin) {
+            if (!using_stdin && (!no_file_overwrite || file_overwrite)) {
                 fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
                 fflush(stderr);
                 if (!read_yesno()) {
@@ -4268,6 +4269,7 @@  static const OptionDef options[] = {
     { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
     { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
+    { "n", OPT_BOOL, {(void*)&no_file_overwrite}, "do not overwrite output files" },
     { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
     { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
     { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },
diff --git a/doc/avconv.texi b/doc/avconv.texi
index 53e9890..854d7a5 100644
--- a/doc/avconv.texi
+++ b/doc/avconv.texi
@@ -113,6 +113,9 @@  input file name
 @item -y (@emph{global})
 Overwrite output files without asking.
 
+@item -n (@emph{global})
+Do not overwrite output files but exit if file exists.
+
 @item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
 @itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
 Select an encoder (when used before an output file) or a decoder (when used
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 2fbfa44..b0d3a45 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -94,6 +94,9 @@  input file name
 @item -y (@emph{global})
 Overwrite output files without asking.
 
+@item -n (@emph{global})
+Do not overwrite output files but exit if file exists.
+
 @item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
 @itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream})
 Select an encoder (when used before an output file) or a decoder (when used
diff --git a/ffmpeg.c b/ffmpeg.c
index 577425b..44139f8 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -131,6 +131,7 @@  static const char *audio_codec_name    = NULL;
 static const char *subtitle_codec_name = NULL;
 
 static int file_overwrite = 0;
+static int no_file_overwrite = 0;
 static int do_benchmark = 0;
 static int do_hex_dump = 0;
 static int do_pkt_dump = 0;
@@ -3247,11 +3248,11 @@  static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
 
 static void assert_file_overwrite(const char *filename)
 {
-    if (!file_overwrite &&
+    if ((!file_overwrite || no_file_overwrite) &&
         (strchr(filename, ':') == NULL || filename[1] == ':' ||
          av_strstart(filename, "file:", NULL))) {
         if (avio_check(filename, 0) == 0) {
-            if (!using_stdin) {
+            if (!using_stdin && (!no_file_overwrite || file_overwrite)) {
                 fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
                 fflush(stderr);
                 term_exit();
@@ -4619,6 +4620,7 @@  static const OptionDef options[] = {
     { "f", HAS_ARG | OPT_STRING | OPT_OFFSET, {.off = OFFSET(format)}, "force format", "fmt" },
     { "i", HAS_ARG | OPT_FUNC2, {(void*)opt_input_file}, "input file name", "filename" },
     { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },
+    { "n", OPT_BOOL, {(void*)&no_file_overwrite}, "do not overwrite output files" },
     { "c", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
     { "codec", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(codec_names)}, "codec name", "codec" },
     { "pre", HAS_ARG | OPT_STRING | OPT_SPEC, {.off = OFFSET(presets)}, "preset name", "preset" },