From aa3d98227e88f316f56aa73a5c6356e3949e9808 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Sat, 5 Nov 2022 21:20:06 +0100 Subject: [PATCH] avcodec/nvenc: don't queue and offset dts for AV1 dts != pts is actually a spec violation for AV1, given it has no reordering in the classical sense. We don't really need the whole timestamp queue in this case and can just pass through the timestamp as is for both dts and pts. --- libavcodec/nvenc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 0d1d68d70d..2583ec2912 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -2170,9 +2170,13 @@ static int nvenc_set_timestamp(AVCodecContext *avctx, NvencContext *ctx = avctx->priv_data; pkt->pts = params->outputTimeStamp; - pkt->dts = timestamp_queue_dequeue(ctx->timestamp_list); - pkt->dts -= FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1); + if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) { + pkt->dts = timestamp_queue_dequeue(ctx->timestamp_list); + pkt->dts -= FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1); + } else { + pkt->dts = pkt->pts; + } return 0; } @@ -2582,7 +2586,9 @@ static int nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame) if (frame && frame->buf[0]) { av_fifo_write(ctx->output_surface_queue, &in_surf, 1); - timestamp_queue_enqueue(ctx->timestamp_list, frame->pts); + + if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) + timestamp_queue_enqueue(ctx->timestamp_list, frame->pts); } /* all the pending buffers are now ready for output */