Message ID | 20210309123154.59060-1-martin@martin.st |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] nvenc: Fix output dts if encoding with implicitly enabled b-frames | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
On Tue, 9 Mar 2021, Martin Storsjö wrote: > Since a0949d0bcb0eee2f3fffcf9a4810c0295d14c0dc, the b-frames > setting defaults to -1, which uses the preset's default setting. > > If b-frames are enabled, but max_b_frames is kept at <= 0, the > output dts are inconsistent. > --- > libavcodec/nvenc.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c > index a061dee880..6baeec6d36 100644 > --- a/libavcodec/nvenc.c > +++ b/libavcodec/nvenc.c > @@ -1380,8 +1380,11 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) > if (res < 0) > return res; > > - if (ctx->encode_config.frameIntervalP > 1) > + if (ctx->encode_config.frameIntervalP > 1) { > avctx->has_b_frames = 2; > + if (avctx->max_b_frames <= 0) > + avctx->max_b_frames = 1; > + } Or maybe we just should change nvenc_set_timestamp to use has_b_frames instead if max_b_frames, iirc that's what's used to signal the number of frames to offset dts elsewhere? Also, as long as the encoder doesn't use something like b-pyramid, shifting dts by 1 should be enough, regardless of the number of b-frames between p-frames. // Martin
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index a061dee880..6baeec6d36 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1380,8 +1380,11 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) if (res < 0) return res; - if (ctx->encode_config.frameIntervalP > 1) + if (ctx->encode_config.frameIntervalP > 1) { avctx->has_b_frames = 2; + if (avctx->max_b_frames <= 0) + avctx->max_b_frames = 1; + } if (ctx->encode_config.rcParams.averageBitRate > 0) avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate;