return 0;
}
-static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
+static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
{
const char *codec_string = encoder ? "encoder" : "decoder";
AVCodec *codec;
- if(!name)
- return CODEC_ID_NONE;
codec = encoder ?
avcodec_find_encoder_by_name(name) :
avcodec_find_decoder_by_name(name);
av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
exit_program(1);
}
- return codec->id;
+ return codec;
}
-static AVCodec *choose_codec(OptionsContext *o, AVFormatContext *s, AVStream *st, enum AVMediaType type)
+static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
{
char *codec_name = NULL;
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
-
- if (!codec_name) {
- if (s->oformat) {
- st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename, NULL, type);
- return avcodec_find_encoder(st->codec->codec_id);
- }
- } else if (!strcmp(codec_name, "copy"))
- st->stream_copy = 1;
- else {
- st->codec->codec_id = find_codec_or_die(codec_name, type, s->iformat == NULL);
- return s->oformat ? avcodec_find_encoder_by_name(codec_name) :
- avcodec_find_decoder_by_name(codec_name);
- }
-
- return NULL;
+ if (codec_name) {
+ AVCodec *codec = find_codec_or_die(codec_name, st->codec->codec_type, 0);
+ st->codec->codec_id = codec->id;
+ return codec;
+ } else
+ return avcodec_find_decoder(st->codec->codec_id);
}
/**
MATCH_PER_STREAM_OPT(ts_scale, dbl, scale, ic, st);
ist->ts_scale = scale;
- ist->dec = choose_codec(o, ic, st, dec->codec_type);
- if (!ist->dec)
- ist->dec = avcodec_find_decoder(dec->codec_id);
+ ist->dec = choose_decoder(o, ic, st);
switch (dec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
/* apply forced codec ids */
for (i = 0; i < ic->nb_streams; i++)
- choose_codec(o, ic, ic->streams[i], ic->streams[i]->codec->codec_type);
+ choose_decoder(o, ic, ic->streams[i]);
/* Set AVCodecContext options for avformat_find_stream_info */
opts = setup_find_stream_info_opts(ic, codec_opts);
return ret;
}
+static void choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
+{
+ char *codec_name = NULL;
+
+ MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
+ if (!codec_name) {
+ ost->st->codec->codec_id = av_guess_codec(s->oformat, NULL, s->filename,
+ NULL, ost->st->codec->codec_type);
+ ost->enc = avcodec_find_encoder(ost->st->codec->codec_id);
+ } else if (!strcmp(codec_name, "copy"))
+ ost->st->stream_copy = 1;
+ else {
+ ost->enc = find_codec_or_die(codec_name, ost->st->codec->codec_type, 1);
+ ost->st->codec->codec_id = ost->enc->id;
+ }
+}
+
static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
{
OutputStream *ost;
ost->index = idx;
ost->st = st;
st->codec->codec_type = type;
- ost->enc = choose_codec(o, oc, st, type);
+ choose_encoder(o, oc, ost);
if (ost->enc) {
ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
}