You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
fftools/ffmpeg: move encoder initialization to init_output_stream_encode
Encoder initialization is currently split rather arbitrarily between init_output_stream_encode() and init_output_stream(). Move all of it to init_output_stream_encode().
This commit is contained in:
@@ -3179,27 +3179,10 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
|
|||||||
if (ost->bitexact)
|
if (ost->bitexact)
|
||||||
enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
|
enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
|
||||||
|
|
||||||
ost->mux_timebase = enc_ctx->time_base;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int init_output_stream(OutputStream *ost, AVFrame *frame)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (ost->enc_ctx) {
|
|
||||||
const AVCodec *codec = ost->enc_ctx->codec;
|
|
||||||
InputStream *ist = ost->ist;
|
|
||||||
|
|
||||||
ret = init_output_stream_encode(ost, frame);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
|
if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
|
||||||
av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
|
av_dict_set(&ost->encoder_opts, "threads", "auto", 0);
|
||||||
|
|
||||||
if (codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) {
|
if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) {
|
||||||
ret = av_dict_set(&ost->encoder_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
|
ret = av_dict_set(&ost->encoder_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -3212,9 +3195,9 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) {
|
if ((ret = avcodec_open2(ost->enc_ctx, enc, &ost->encoder_opts)) < 0) {
|
||||||
if (ret == AVERROR_EXPERIMENTAL)
|
if (ret == AVERROR_EXPERIMENTAL)
|
||||||
abort_codec_experimental(codec, 1);
|
abort_codec_experimental(enc, 1);
|
||||||
av_log(ost, AV_LOG_ERROR, "Error while opening encoder - maybe "
|
av_log(ost, AV_LOG_ERROR, "Error while opening encoder - maybe "
|
||||||
"incorrect parameters such as bit_rate, rate, width or height.\n");
|
"incorrect parameters such as bit_rate, rate, width or height.\n");
|
||||||
return ret;
|
return ret;
|
||||||
@@ -3282,6 +3265,20 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame)
|
|||||||
// copy estimated duration as a hint to the muxer
|
// copy estimated duration as a hint to the muxer
|
||||||
if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
|
if (ost->st->duration <= 0 && ist && ist->st->duration > 0)
|
||||||
ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
|
ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base);
|
||||||
|
|
||||||
|
ost->mux_timebase = enc_ctx->time_base;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int init_output_stream(OutputStream *ost, AVFrame *frame)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (ost->enc_ctx) {
|
||||||
|
ret = init_output_stream_encode(ost, frame);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
} else if (ost->ist) {
|
} else if (ost->ist) {
|
||||||
ret = init_output_stream_streamcopy(ost);
|
ret = init_output_stream_streamcopy(ost);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Reference in New Issue
Block a user