X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_opt.c;h=2cdc56dacc7e4a23176dedcbd09a338f909e3863;hb=255302da7019753bae84d809c6d603c4cd0a41ca;hp=c9283d69fabdceb4253ce5064d11cb9a8e51333a;hpb=0db04ca01dfa34659abc407648bdac507df297f5;p=ffmpeg diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index c9283d69fab..2cdc56dacc7 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -1151,26 +1151,36 @@ static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost) { AVStream *st = ost->st; - char *filter = NULL, *filter_script = NULL; - MATCH_PER_STREAM_OPT(filter_scripts, str, filter_script, oc, st); - MATCH_PER_STREAM_OPT(filters, str, filter, oc, st); - - if (filter_script && filter) { + if (ost->filters_script && ost->filters) { av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for " "output stream #%d:%d.\n", nb_output_files, st->index); exit_program(1); } - if (filter_script) - return read_file(filter_script); - else if (filter) - return av_strdup(filter); + if (ost->filters_script) + return read_file(ost->filters_script); + else if (ost->filters) + return av_strdup(ost->filters); return av_strdup(st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "null" : "anull"); } +static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, + const OutputStream *ost, enum AVMediaType type) +{ + if (ost->filters_script || ost->filters) { + av_log(NULL, AV_LOG_ERROR, + "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n" + "Filtering and streamcopy cannot be used together.\n", + ost->filters ? "Filtergraph" : "Filtergraph script", + ost->filters ? ost->filters : ost->filters_script, + av_get_media_type_string(type), ost->file_index, ost->index); + exit_program(1); + } +} + static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index) { AVStream *st; @@ -1199,6 +1209,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->frame_aspect_ratio = q; } + MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); + MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); + if (!ost->stream_copy) { const char *p = NULL; char *frame_size = NULL; @@ -1311,6 +1324,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st); } + if (ost->stream_copy) + check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO); + return ost; } @@ -1327,6 +1343,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in audio_enc = st->codec; audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; + MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); + MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st); + if (!ost->stream_copy) { char *sample_fmt = NULL; @@ -1364,6 +1383,9 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in } } + if (ost->stream_copy) + check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO); + return ost; } @@ -1548,6 +1570,18 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, exit_program(1); } + if (ost->avfilter && (ost->filters || ost->filters_script)) { + const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script"; + av_log(NULL, AV_LOG_ERROR, + "%s '%s' was specified through the %s option " + "for output stream %d:%d, which is fed from a complex filtergraph.\n" + "%s and -filter_complex cannot be used together for the same stream.\n", + ost->filters ? "Filtergraph" : "Filtergraph script", + ost->filters ? ost->filters : ost->filters_script, + opt, ost->file_index, ost->index, opt); + exit_program(1); + } + if (configure_output_filter(ofilter->graph, ofilter, ofilter->out_tmp) < 0) { av_log(NULL, AV_LOG_FATAL, "Error configuring filter.\n"); exit_program(1);