X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_opt.c;h=aabcfc0446899227749778bc33d416b58e1f80c2;hb=8f4b176c55f05291c85a32d55e07db1612bf93ea;hp=eeacf5828cc21b6d1b4888be00cf1cf4d1f6ade4;hpb=48a691630833d6b12905475b6bf39fef285872a9;p=ffmpeg diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index eeacf5828cc..aabcfc04468 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -564,7 +564,7 @@ static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream * * list of input streams. */ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) { - int i; + int i, ret; for (i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; @@ -604,6 +604,18 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + ist->dec_ctx = avcodec_alloc_context3(ist->dec); + if (!ist->dec_ctx) { + av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n"); + exit_program(1); + } + + ret = avcodec_copy_context(ist->dec_ctx, dec); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n"); + exit_program(1); + } + switch (dec->codec_type) { case AVMEDIA_TYPE_VIDEO: if(!ist->dec) @@ -612,9 +624,9 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) dec->flags |= CODEC_FLAG_EMU_EDGE; } - ist->resample_height = dec->height; - ist->resample_width = dec->width; - ist->resample_pix_fmt = dec->pix_fmt; + ist->resample_height = ist->dec_ctx->height; + ist->resample_width = ist->dec_ctx->width; + ist->resample_pix_fmt = ist->dec_ctx->pix_fmt; MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st); if (framerate && av_parse_video_rate(&ist->framerate, @@ -668,10 +680,10 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st); guess_input_channel_layout(ist); - ist->resample_sample_fmt = dec->sample_fmt; - ist->resample_sample_rate = dec->sample_rate; - ist->resample_channels = dec->channels; - ist->resample_channel_layout = dec->channel_layout; + ist->resample_sample_fmt = ist->dec_ctx->sample_fmt; + ist->resample_sample_rate = ist->dec_ctx->sample_rate; + ist->resample_channels = ist->dec_ctx->channels; + ist->resample_channel_layout = ist->dec_ctx->channel_layout; break; case AVMEDIA_TYPE_DATA: @@ -1053,6 +1065,14 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->st = st; st->codec->codec_type = type; choose_encoder(o, oc, ost); + + ost->enc_ctx = avcodec_alloc_context3(ost->enc); + if (!ost->enc_ctx) { + av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); + exit_program(1); + } + ost->enc_ctx->codec_type = type; + if (ost->enc) { AVIOContext *s = NULL; char *buf = NULL, *arg = NULL, *preset = NULL; @@ -1087,9 +1107,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); } - 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 - ost->max_frames = INT64_MAX; MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); for (i = 0; inb_max_frames; i++) { @@ -1125,17 +1142,17 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e uint32_t tag = strtol(codec_tag, &next, 0); if (*next) tag = AV_RL32(codec_tag); - st->codec->codec_tag = tag; + ost->enc_ctx->codec_tag = tag; } MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st); if (qscale >= 0) { - st->codec->flags |= CODEC_FLAG_QSCALE; - st->codec->global_quality = FF_QP2LAMBDA * qscale; + ost->enc_ctx->flags |= CODEC_FLAG_QSCALE; + ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale; } if (oc->oformat->flags & AVFMT_GLOBALHEADER) - st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; + ost->enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER; av_opt_get_int(o->g->sws_opts, "sws_flags", 0, &ost->sws_flags); @@ -1245,7 +1262,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index); st = ost->st; - video_enc = st->codec; + video_enc = ost->enc_ctx; MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st); if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { @@ -1406,7 +1423,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index); st = ost->st; - audio_enc = st->codec; + audio_enc = ost->enc_ctx; audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st); @@ -1496,7 +1513,7 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index); st = ost->st; - subtitle_enc = st->codec; + subtitle_enc = ost->enc_ctx; subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; @@ -1614,7 +1631,8 @@ static int read_ffserver_streams(OptionsContext *o, AVFormatContext *s, const ch if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && !ost->stream_copy) choose_sample_fmt(st, codec); else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && !ost->stream_copy) - choose_pixel_fmt(st, codec, st->codec->pix_fmt); + choose_pixel_fmt(st, st->codec, codec, st->codec->pix_fmt); + avcodec_copy_context(ost->enc_ctx, st->codec); } avformat_close_input(&ic); @@ -1932,8 +1950,8 @@ loop_end: ost->stream_copy = 0; ost->attachment_filename = o->attachments[i]; ost->finished = 1; - ost->st->codec->extradata = attachment; - ost->st->codec->extradata_size = len; + ost->enc_ctx->extradata = attachment; + ost->enc_ctx->extradata_size = len; p = strrchr(o->attachments[i], '/'); av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);