X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=avconv_opt.c;h=ffb6c650ce8cb321505fcb77598a988dc5cab13e;hb=02e4275180866acc0f42281d1c5ef5a46552da84;hp=058d5a37795ac3c4162514072562b612884bb105;hpb=c1ef30a6ba2cdc15147c4e80766e9bda629ffc1d;p=ffmpeg diff --git a/avconv_opt.c b/avconv_opt.c index 058d5a37795..ffb6c650ce8 100644 --- a/avconv_opt.c +++ b/avconv_opt.c @@ -276,6 +276,7 @@ static int opt_attach(void *optctx, const char *opt, const char *arg) /** * Parse a metadata specifier passed as 'arg' parameter. + * @param arg metadata string to parse * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram) * @param index for type c/p, chapter/program index is written here * @param stream_spec for type s, the stream specifier is written here @@ -326,6 +327,10 @@ static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFor if (type_in == 'c' || type_out == 'c') o->metadata_chapters_manual = 1; + /* ic is NULL when just disabling automatic mappings */ + if (!ic) + return 0; + #define METADATA_CHECK_INDEX(index, nb_elems, desc)\ if ((index) < 0 || (index) >= (nb_elems)) {\ av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\ @@ -750,8 +755,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e char *bsf = NULL, *next, *codec_tag = NULL; AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; double qscale = -1; - char *buf = NULL, *arg = NULL, *preset = NULL; - AVIOContext *s = NULL; if (!st) { av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); @@ -773,37 +776,40 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e st->codec->codec_type = type; choose_encoder(o, oc, ost); if (ost->enc) { + AVIOContext *s = NULL; + char *buf = NULL, *arg = NULL, *preset = NULL; + ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st, ost->enc); + + MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); + if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { + do { + buf = get_line(s); + if (!buf[0] || buf[0] == '#') { + av_free(buf); + continue; + } + if (!(arg = strchr(buf, '='))) { + av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); + exit(1); + } + *arg++ = 0; + av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE); + av_free(buf); + } while (!s->eof_reached); + avio_close(s); + } + if (ret) { + av_log(NULL, AV_LOG_FATAL, + "Preset %s specified for stream %d:%d, but could not be opened.\n", + preset, ost->file_index, ost->index); + exit(1); + } } avcodec_get_context_defaults3(st->codec, ost->enc); st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy - MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); - if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { - do { - buf = get_line(s); - if (!buf[0] || buf[0] == '#') { - av_free(buf); - continue; - } - if (!(arg = strchr(buf, '='))) { - av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); - exit(1); - } - *arg++ = 0; - av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE); - av_free(buf); - } while (!s->eof_reached); - avio_close(s); - } - if (ret) { - av_log(NULL, AV_LOG_FATAL, - "Preset %s specified for stream %d:%d, but could not be opened.\n", - preset, ost->file_index, ost->index); - exit(1); - } - ost->max_frames = INT64_MAX; MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); @@ -1410,13 +1416,13 @@ loop_end: char *p; int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0); - if (in_file_index < 0) - continue; if (in_file_index >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); exit(1); } - copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index]->ctx, o); + copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, + in_file_index >= 0 ? + input_files[in_file_index]->ctx : NULL, o); } /* copy chapters */