[FFmpeg-devel] [PATCH] ffmpeg_opt: Do not overwrite output if there is no input

Alexander Strasser eclipse7 at gmx.net
Sat Mar 28 03:21:17 CET 2015


Hi all,
hi Michael!

  I have attached the solution I worked on. It is
probably inferior to yours. I honestly don't know
and didn't think to hard about it. It passes my
basic tests and fate at least.

  Just posting for completeness and maybe I will
learn something new.
 
Thank you,
  Alexander

On 2015-03-27 02:11 +0100, Michael Niedermayer wrote:
> Fixes Ticket4254
> 
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  ffmpeg_opt.c |   15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
> index 39c5f49..fb7490a 100644
> --- a/ffmpeg_opt.c
> +++ b/ffmpeg_opt.c
> @@ -110,6 +110,7 @@ static int no_file_overwrite  = 0;
>  static int do_psnr            = 0;
>  static int input_sync;
>  static int override_ffserver  = 0;
> +static int input_stream_potentially_available = 0;
>  
>  static void uninit_options(OptionsContext *o)
>  {
> @@ -1008,6 +1009,8 @@ static int open_input_file(OptionsContext *o, const char *filename)
>          av_dict_free(&opts[i]);
>      av_freep(&opts);
>  
> +    input_stream_potentially_available = 1;
> +
>      return 0;
>  }
>  
> @@ -2104,6 +2107,12 @@ loop_end:
>          }
>      }
>  
> +    if (!(oc->oformat->flags & AVFMT_NOSTREAMS) && !input_stream_potentially_available) {
> +        av_log(NULL, AV_LOG_ERROR,
> +               "No input streams but output needs an input stream\n");
> +        exit_program(1);
> +    }
> +
>      if (!(oc->oformat->flags & AVFMT_NOFILE)) {
>          /* test if it already exists to avoid losing precious files */
>          assert_file_overwrite(filename);
> @@ -2608,6 +2617,9 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
>      filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg);
>      if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
>          return AVERROR(ENOMEM);
> +
> +    input_stream_potentially_available = 1;
> +
>      return 0;
>  }
>  
> @@ -2622,6 +2634,9 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char *
>          return AVERROR(ENOMEM);
>      filtergraphs[nb_filtergraphs - 1]->index      = nb_filtergraphs - 1;
>      filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
> +
> +    input_stream_potentially_available = 1;
> +
>      return 0;
>  }
>  
> -- 
-------------- next part --------------
From dbf318b0068d04fbe5d2890f6a7e376e092a8219 Mon Sep 17 00:00:00 2001
Message-Id: <dbf318b0068d04fbe5d2890f6a7e376e092a8219.1427509156.git.eclipse7 at gmx.net>
From: Alexander Strasser <eclipse7 at gmx.net>
Date: Sat, 28 Mar 2015 02:55:59 +0100
Subject: [PATCH] ffmpeg: Don't overwrite output files if no inputs are
 possibly given

Fix ticket #4254

Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 ffmpeg.c     | 5 -----
 ffmpeg_opt.c | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 67ce1f3..e604de8 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4027,11 +4027,6 @@ int main(int argc, char **argv)
         exit_program(1);
     }
 
-//     if (nb_input_files == 0) {
-//         av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n");
-//         exit_program(1);
-//     }
-
     current_time = ti = getutime();
     if (transcode() < 0)
         exit_program(1);
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 39c5f49..fa1ffe8 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -2773,6 +2773,12 @@ int ffmpeg_parse_options(int argc, char **argv)
         goto fail;
     }
 
+    if (nb_input_files == 0 && nb_filtergraphs == 0) {
+        av_log(NULL, AV_LOG_FATAL, "At least one input file (or filter source) must be specified: ");
+	ret = AVERROR(EINVAL);
+        goto fail;
+    }
+
     /* open output files */
     ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
     if (ret < 0) {
-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150328/38c39b2a/attachment.asc>


More information about the ffmpeg-devel mailing list