summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-07-12 14:37:15 +0200
committerAnton Khirnov <anton@khirnov.net>2022-08-23 16:50:33 +0200
commitccb919f86cb5c046f7453400db10feb23c6ce483 (patch)
tree4141fee45d00d78285b22f8b3c7b10ab4b6916eb
parentec8bd87d8d858457c9d3d4327ced170eda6c6c70 (diff)
lavc/libx265: pass through frame durations to encoded packets
-rw-r--r--libavcodec/libx265.c29
1 files 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;