diff options
-rw-r--r-- | libavcodec/librav1e.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c index 67b301b802..8985f32356 100644 --- a/libavcodec/librav1e.c +++ b/libavcodec/librav1e.c @@ -55,6 +55,11 @@ typedef struct librav1eContext { int tile_cols; } librav1eContext; +typedef struct FrameTiming { + int64_t pts; + int64_t duration; +} FrameTiming; + static inline RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range) { switch (pix_fmt) { @@ -435,6 +440,7 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt) librav1eContext *ctx = avctx->priv_data; RaFrame *rframe = ctx->rframe; RaPacket *rpkt = NULL; + FrameTiming *ts; int ret; if (!rframe) { @@ -447,18 +453,19 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt) if (frame->buf[0]) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); - int64_t *pts = av_malloc(sizeof(int64_t)); - if (!pts) { + ts = av_malloc(sizeof(*ts)); + if (!ts) { av_log(avctx, AV_LOG_ERROR, "Could not allocate PTS buffer.\n"); return AVERROR(ENOMEM); } - *pts = frame->pts; + ts->pts = frame->pts; + ts->duration = frame->duration; rframe = rav1e_frame_new(ctx->ctx); if (!rframe) { av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n"); av_frame_unref(frame); - av_freep(&pts); + av_freep(&ts); return AVERROR(ENOMEM); } @@ -470,7 +477,7 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt) frame->linesize[i], bytes); } av_frame_unref(frame); - rav1e_frame_set_opaque(rframe, pts, av_free); + rav1e_frame_set_opaque(rframe, ts, av_free); } } @@ -546,8 +553,10 @@ retry: if (rpkt->frame_type == RA_FRAME_TYPE_KEY) pkt->flags |= AV_PKT_FLAG_KEY; - pkt->pts = pkt->dts = *((int64_t *) rpkt->opaque); - av_free(rpkt->opaque); + ts = rpkt->opaque; + pkt->pts = pkt->dts = ts->pts; + pkt->duration = ts->duration; + av_freep(&ts); rav1e_packet_unref(rpkt); if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { |