From ccb919f86cb5c046f7453400db10feb23c6ce483 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jul 2022 14:37:15 +0200 Subject: lavc/libx265: pass through frame durations to encoded packets --- libavcodec/libx265.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 6d2590dd7f..b10fff2ebe 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -38,6 +38,11 @@ #include "packet_internal.h" #include "sei.h" +typedef struct ReorderedData { + int64_t reordered_opaque; + int64_t duration; +} ReorderedData; + typedef struct libx265Context { const AVClass *class; @@ -506,6 +511,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, x265_picture x265pic; x265_picture x265pic_out = { 0 }; x265_nal *nal; + ReorderedData *rd; uint8_t *dst; int pict_type; int payload = 0; @@ -536,16 +542,17 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (ret < 0) return ret; - if (pic->reordered_opaque) { - x265pic.userData = av_malloc(sizeof(pic->reordered_opaque)); - if (!x265pic.userData) { - av_freep(&x265pic.quantOffsets); - return AVERROR(ENOMEM); - } - - memcpy(x265pic.userData, &pic->reordered_opaque, sizeof(pic->reordered_opaque)); + rd = av_mallocz(sizeof(*rd)); + if (!rd) { + av_freep(&x265pic.quantOffsets); + return AVERROR(ENOMEM); } + rd->duration = pic->duration; + rd->reordered_opaque = pic->reordered_opaque; + + x265pic.userData = rd; + if (ctx->udu_sei) { for (i = 0; i < pic->nb_side_data; i++) { AVFrameSideData *side_data = pic->side_data[i]; @@ -633,8 +640,10 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ff_side_data_set_encoder_stats(pkt, x265pic_out.frameData.qp * FF_QP2LAMBDA, NULL, 0, pict_type); - if (x265pic_out.userData) { - memcpy(&avctx->reordered_opaque, x265pic_out.userData, sizeof(avctx->reordered_opaque)); + rd = x265pic_out.userData; + if (rd) { + avctx->reordered_opaque = rd->reordered_opaque; + pkt->duration = rd->duration; av_freep(&x265pic_out.userData); } else avctx->reordered_opaque = 0; -- cgit v1.2.3