diff options
author | Gyan Doshi <ffmpeg@gyani.pro> | 2018-08-26 11:22:50 +0530 |
---|---|---|
committer | Gyan Doshi <ffmpeg@gyani.pro> | 2018-09-17 13:48:28 +0530 |
commit | acc9684dcd3949741e944d611f5a2a62db0546e6 (patch) | |
tree | d30bce3b007d7adad6621b920ea89019464a9480 /fftools | |
parent | 5109c381628d53e4fbfa8605e40290e86291e498 (diff) | |
download | ffmpeg-acc9684dcd3949741e944d611f5a2a62db0546e6.tar.gz |
ffmpeg: block output == input for files
Fixes #4655
Diffstat (limited to 'fftools')
-rw-r--r-- | fftools/ffmpeg_opt.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 58ec13e5a8..c44ed63730 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -900,13 +900,14 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) static void assert_file_overwrite(const char *filename) { + const char *proto_name = avio_find_protocol_name(filename); + if (file_overwrite && no_file_overwrite) { fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n"); exit_program(1); } if (!file_overwrite) { - const char *proto_name = avio_find_protocol_name(filename); if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) { if (stdin_interaction && !no_file_overwrite) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); @@ -925,6 +926,19 @@ static void assert_file_overwrite(const char *filename) } } } + + if (proto_name && !strcmp(proto_name, "file")) { + for (int i = 0; i < nb_input_files; i++) { + InputFile *file = input_files[i]; + if (file->ctx->iformat->flags & AVFMT_NOFILE) + continue; + if (!strcmp(filename, file->ctx->url)) { + av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i); + av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n"); + exit_program(1); + } + } + } } static void dump_attachment(AVStream *st, const char *filename) |