forked from FFmpeg/FFmpeg
fftools/cmdutils: add error handling to filter_codec_opts()
This commit is contained in:
parent
6b8cf2505a
commit
87f0333af1
6 changed files with 56 additions and 23 deletions
|
@ -943,8 +943,9 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
|
|||
return ret;
|
||||
}
|
||||
|
||||
AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
|
||||
AVFormatContext *s, AVStream *st, const AVCodec *codec)
|
||||
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
|
||||
AVFormatContext *s, AVStream *st, const AVCodec *codec,
|
||||
AVDictionary **dst)
|
||||
{
|
||||
AVDictionary *ret = NULL;
|
||||
const AVDictionaryEntry *t = NULL;
|
||||
|
@ -977,11 +978,15 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i
|
|||
char *p = strchr(t->key, ':');
|
||||
|
||||
/* check stream specification in opt name */
|
||||
if (p)
|
||||
switch (check_stream_specifier(s, st, p + 1)) {
|
||||
case 1: *p = 0; break;
|
||||
case 0: continue;
|
||||
default: exit_program(1);
|
||||
if (p) {
|
||||
int err = check_stream_specifier(s, st, p + 1);
|
||||
if (err < 0) {
|
||||
av_dict_free(&ret);
|
||||
return err;
|
||||
} else if (!err)
|
||||
continue;
|
||||
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
|
||||
|
@ -998,14 +1003,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i
|
|||
if (p)
|
||||
*p = ':';
|
||||
}
|
||||
return ret;
|
||||
|
||||
*dst = ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setup_find_stream_info_opts(AVFormatContext *s,
|
||||
AVDictionary *codec_opts,
|
||||
AVDictionary ***dst)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
AVDictionary **opts;
|
||||
|
||||
*dst = NULL;
|
||||
|
@ -1017,11 +1024,19 @@ int setup_find_stream_info_opts(AVFormatContext *s,
|
|||
if (!opts)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
for (i = 0; i < s->nb_streams; i++)
|
||||
opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
|
||||
s, s->streams[i], NULL);
|
||||
for (int i = 0; i < s->nb_streams; i++) {
|
||||
ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
|
||||
s, s->streams[i], NULL, &opts[i]);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
}
|
||||
*dst = opts;
|
||||
return 0;
|
||||
fail:
|
||||
for (int i = 0; i < s->nb_streams; i++)
|
||||
av_dict_free(&opts[i]);
|
||||
av_freep(&opts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grow_array(void **array, int elem_size, int *size, int new_size)
|
||||
|
|
|
@ -333,10 +333,12 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec);
|
|||
* @param st A stream from s for which the options should be filtered.
|
||||
* @param codec The particular codec for which the options should be filtered.
|
||||
* If null, the default one is looked up according to the codec id.
|
||||
* @return a pointer to the created dictionary
|
||||
* @param dst a pointer to the created dictionary
|
||||
* @return a non-negative number on success, a negative error code on failure
|
||||
*/
|
||||
AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
|
||||
AVFormatContext *s, AVStream *st, const AVCodec *codec);
|
||||
int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
|
||||
AVFormatContext *s, AVStream *st, const AVCodec *codec,
|
||||
AVDictionary **dst);
|
||||
|
||||
/**
|
||||
* Setup AVCodecContext options for avformat_find_stream_info().
|
||||
|
|
|
@ -1176,7 +1176,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
|
||||
ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
|
||||
ic, st, ist->dec, &ist->decoder_opts);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ist->reinit_filters = -1;
|
||||
MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
|
||||
|
|
|
@ -1206,8 +1206,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
|
|||
const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
|
||||
const char *enc_time_base = NULL;
|
||||
|
||||
ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id,
|
||||
oc, st, enc->codec);
|
||||
ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
|
||||
oc, st, enc->codec, &ost->encoder_opts);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
|
||||
ost->autoscale = 1;
|
||||
|
@ -1305,7 +1307,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
|
|||
ost->enc_timebase = q;
|
||||
}
|
||||
} else {
|
||||
ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
|
||||
ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
|
||||
NULL, &ost->encoder_opts);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2584,7 +2584,11 @@ static int stream_component_open(VideoState *is, int stream_index)
|
|||
if (fast)
|
||||
avctx->flags2 |= AV_CODEC_FLAG2_FAST;
|
||||
|
||||
opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec);
|
||||
ret = filter_codec_opts(codec_opts, avctx->codec_id, ic,
|
||||
ic->streams[stream_index], codec, &opts);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
|
||||
if (!av_dict_get(opts, "threads", NULL, 0))
|
||||
av_dict_set(&opts, "threads", "auto", 0);
|
||||
if (stream_lowres)
|
||||
|
|
|
@ -3421,8 +3421,12 @@ static int open_input_file(InputFile *ifile, const char *filename,
|
|||
continue;
|
||||
}
|
||||
{
|
||||
AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
|
||||
fmt_ctx, stream, codec);
|
||||
AVDictionary *opts;
|
||||
|
||||
err = filter_codec_opts(codec_opts, stream->codecpar->codec_id,
|
||||
fmt_ctx, stream, codec, &opts);
|
||||
if (err < 0)
|
||||
exit(1);
|
||||
|
||||
ist->dec_ctx = avcodec_alloc_context3(codec);
|
||||
if (!ist->dec_ctx)
|
||||
|
|
Loading…
Add table
Reference in a new issue