Skip to content

Commit

Permalink
upipe_avfilter: fix video uref duration
Browse files Browse the repository at this point in the history
  • Loading branch information
nto authored and cmassiot committed Feb 17, 2025
1 parent d27a083 commit a62282f
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/upipe-av/upipe_avfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,10 @@ upipe_avfilt_sub_frame_to_uref(struct upipe *upipe, AVFrame *frame)
uint64_t now = upipe_avfilt_sub_now(upipe);

/* set pts orig */
AVRational av_time_base = av_buffersink_get_time_base(
AVRational time_base = av_buffersink_get_time_base(
upipe_avfilt_sub->buffer_ctx);
struct urational to = { .num = UCLOCK_FREQ, .den = 1 };
struct urational from = {
.num = av_time_base.num,
.den = av_time_base.den
};
struct urational mult = urational_multiply(&to, &from);
uint64_t pts_orig = frame->pts * mult.num / mult.den;
uint64_t pts_orig = av_rescale_q(frame->pts, time_base,
av_make_q(1, UCLOCK_FREQ));
uint64_t pts_prog = pts_orig + upipe_avfilt_sub->pts_prog_offset;
if (upipe_avfilt_sub->last_pts_prog != UINT64_MAX) {
if (pts_prog <= upipe_avfilt_sub->last_pts_prog) {
Expand Down Expand Up @@ -739,7 +734,8 @@ upipe_avfilt_sub_frame_to_uref(struct upipe *upipe, AVFrame *frame)
uint64_t duration = 0;
switch (media_type) {
case AVMEDIA_TYPE_VIDEO:
duration = frame->pkt_duration;
duration = av_rescale_q(frame->pkt_duration, time_base,
av_make_q(1, UCLOCK_FREQ));

if (!frame->interlaced_frame)
UBASE_ERROR(upipe, uref_pic_set_progressive(uref))
Expand Down Expand Up @@ -2212,6 +2208,9 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
{
struct upipe_avfilt *upipe_avfilt = upipe_avfilt_from_upipe(upipe);

AVRational time_base = av_buffersink_get_time_base(
upipe_avfilt->buffersink_ctx);

if (unlikely(!upipe_avfilt->flow_def)) {
struct uref *flow_def_attr = upipe_avfilt_alloc_flow_def_attr(upipe);
if (flow_def_attr == NULL) {
Expand All @@ -2233,8 +2232,6 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,

uint64_t latency = 0;
if (frame->pts != AV_NOPTS_VALUE) {
AVRational time_base = av_buffersink_get_time_base(
upipe_avfilt->buffersink_ctx);
uint64_t pts = av_rescale_q(frame->pts, time_base,
av_make_q(1, UCLOCK_FREQ));
uint64_t input_pts;
Expand Down Expand Up @@ -2293,12 +2290,8 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
uint64_t pts_prog = UINT64_MAX;
uint64_t pts_sys = UINT64_MAX;
if (frame->pts != AV_NOPTS_VALUE) {
AVRational time_base = av_buffersink_get_time_base(
upipe_avfilt->buffersink_ctx);
struct urational to = { .num = UCLOCK_FREQ, .den = 1 };
struct urational from = { .num = time_base.num, .den = time_base.den };
struct urational mult = urational_multiply(&to, &from);
uint64_t pts = frame->pts * mult.num / mult.den;
uint64_t pts = av_rescale_q(frame->pts, time_base,
av_make_q(1, UCLOCK_FREQ));

if (ubase_check(uref_clock_get_pts_prog(uref, &pts_prog)) &&
ubase_check(uref_clock_get_pts_sys(uref, &pts_sys))) {
Expand All @@ -2312,7 +2305,8 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
uint64_t duration = 0;
switch (media_type) {
case AVMEDIA_TYPE_VIDEO:
duration = frame->pkt_duration;
duration = av_rescale_q(frame->pkt_duration, time_base,
av_make_q(1, UCLOCK_FREQ));

if (!frame->interlaced_frame)
UBASE_ERROR(upipe, uref_pic_set_progressive(uref))
Expand Down

0 comments on commit a62282f

Please sign in to comment.