fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting

pull/389/head
Anton Khirnov 1 year ago
parent 2d59873fc1
commit cce294638b
  1. 2
      fftools/ffmpeg.h
  2. 4
      fftools/ffmpeg_demux.c
  3. 11
      fftools/ffmpeg_mux_init.c
  4. 12
      fftools/ffmpeg_opt.c

@ -700,7 +700,7 @@ void show_usage(void);
void remove_avoptions(AVDictionary **a, AVDictionary *b);
void assert_avoptions(AVDictionary *m);
void assert_file_overwrite(const char *filename);
int assert_file_overwrite(const char *filename);
char *file_read(const char *filename);
AVDictionary *strip_specifiers(const AVDictionary *dict);
const AVCodec *find_codec_or_die(void *logctx, const char *name,

@ -1277,7 +1277,9 @@ static int dump_attachment(InputStream *ist, const char *filename)
return AVERROR(EINVAL);
}
assert_file_overwrite(filename);
ret = assert_file_overwrite(filename);
if (ret < 0)
return ret;
if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",

@ -2442,7 +2442,9 @@ int of_open(const OptionsContext *o, const char *filename)
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
/* test if it already exists to avoid losing precious files */
assert_file_overwrite(filename);
err = assert_file_overwrite(filename);
if (err < 0)
return err;
/* open the file */
if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
@ -2452,8 +2454,11 @@ int of_open(const OptionsContext *o, const char *filename)
filename, av_err2str(err));
return err;
}
} else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
assert_file_overwrite(filename);
} else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) {
err = assert_file_overwrite(filename);
if (err < 0)
return err;
}
if (o->mux_preload) {
av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);

@ -652,13 +652,13 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name,
return codec;
}
void assert_file_overwrite(const char *filename)
int 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);
return AVERROR(EINVAL);
}
if (!file_overwrite) {
@ -670,13 +670,13 @@ void assert_file_overwrite(const char *filename)
signal(SIGINT, SIG_DFL);
if (!read_yesno()) {
av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
exit_program(1);
return AVERROR_EXIT;
}
term_init();
}
else {
av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
exit_program(1);
return AVERROR_EXIT;
}
}
}
@ -689,10 +689,12 @@ void assert_file_overwrite(const char *filename)
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);
return AVERROR(EINVAL);
}
}
}
return 0;
}
/* read file contents into a string */

Loading…
Cancel
Save