Skip to content

Commit e55a80d

Browse files
committed
avcodec/librav1e: Pass through timestamps as opaque user data
avcodec has no facilities to generate timestamps properly from output frame numbers (and it would be wrong for VFR anyway), so pass through the timestamps using rav1e's opaque user data feature, which was added in v0.4.0. This bumps the minimum librav1e version to 0.4.0. Signed-off-by: Derek Buitenhuis <[email protected]>
1 parent f975cf7 commit e55a80d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -6408,7 +6408,7 @@ enabled libopus && {
64086408
}
64096409
enabled libpulse && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new
64106410
enabled librabbitmq && require_pkg_config librabbitmq "librabbitmq >= 0.7.1" amqp.h amqp_new_connection
6411-
enabled librav1e && require_pkg_config librav1e "rav1e >= 0.1.0" rav1e.h rav1e_context_new
6411+
enabled librav1e && require_pkg_config librav1e "rav1e >= 0.4.0" rav1e.h rav1e_context_new
64126412
enabled librsvg && require_pkg_config librsvg librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
64136413
enabled librtmp && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket
64146414
enabled librubberband && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new -lstdc++ && append librubberband_extralibs "-lstdc++"

libavcodec/librav1e.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,18 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
445445
if (frame->buf[0]) {
446446
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
447447

448+
int64_t *pts = av_malloc(sizeof(int64_t));
449+
if (!pts) {
450+
av_log(avctx, AV_LOG_ERROR, "Could not allocate PTS buffer.\n");
451+
return AVERROR(ENOMEM);
452+
}
453+
*pts = frame->pts;
454+
448455
rframe = rav1e_frame_new(ctx->ctx);
449456
if (!rframe) {
450457
av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n");
451458
av_frame_unref(frame);
459+
av_freep(&pts);
452460
return AVERROR(ENOMEM);
453461
}
454462

@@ -460,6 +468,7 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
460468
frame->linesize[i], bytes);
461469
}
462470
av_frame_unref(frame);
471+
rav1e_frame_set_opaque(rframe, pts, av_free);
463472
}
464473
}
465474

@@ -535,7 +544,8 @@ static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
535544
if (rpkt->frame_type == RA_FRAME_TYPE_KEY)
536545
pkt->flags |= AV_PKT_FLAG_KEY;
537546

538-
pkt->pts = pkt->dts = rpkt->input_frameno * avctx->ticks_per_frame;
547+
pkt->pts = pkt->dts = *((int64_t *) rpkt->opaque);
548+
av_free(rpkt->opaque);
539549
rav1e_packet_unref(rpkt);
540550

541551
if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {

0 commit comments

Comments
 (0)