Skip to content

Commit a9582c9

Browse files
committed
upipe_avfilter: fix video uref duration
1 parent c39ff44 commit a9582c9

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

lib/upipe-av/upipe_avfilter.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -691,15 +691,10 @@ upipe_avfilt_sub_frame_to_uref(struct upipe *upipe, AVFrame *frame)
691691
uint64_t now = upipe_avfilt_sub_now(upipe);
692692

693693
/* set pts orig */
694-
AVRational av_time_base = av_buffersink_get_time_base(
694+
AVRational time_base = av_buffersink_get_time_base(
695695
upipe_avfilt_sub->buffer_ctx);
696-
struct urational to = { .num = UCLOCK_FREQ, .den = 1 };
697-
struct urational from = {
698-
.num = av_time_base.num,
699-
.den = av_time_base.den
700-
};
701-
struct urational mult = urational_multiply(&to, &from);
702-
uint64_t pts_orig = frame->pts * mult.num / mult.den;
696+
uint64_t pts_orig = av_rescale_q(frame->pts, time_base,
697+
av_make_q(1, UCLOCK_FREQ));
703698
uint64_t pts_prog = pts_orig + upipe_avfilt_sub->pts_prog_offset;
704699
if (upipe_avfilt_sub->last_pts_prog != UINT64_MAX) {
705700
if (pts_prog <= upipe_avfilt_sub->last_pts_prog) {
@@ -739,7 +734,8 @@ upipe_avfilt_sub_frame_to_uref(struct upipe *upipe, AVFrame *frame)
739734
uint64_t duration = 0;
740735
switch (media_type) {
741736
case AVMEDIA_TYPE_VIDEO:
742-
duration = frame->pkt_duration;
737+
duration = av_rescale_q(frame->pkt_duration, time_base,
738+
av_make_q(1, UCLOCK_FREQ));
743739

744740
if (!frame->interlaced_frame)
745741
UBASE_ERROR(upipe, uref_pic_set_progressive(uref))
@@ -2212,6 +2208,9 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
22122208
{
22132209
struct upipe_avfilt *upipe_avfilt = upipe_avfilt_from_upipe(upipe);
22142210

2211+
AVRational time_base = av_buffersink_get_time_base(
2212+
upipe_avfilt->buffersink_ctx);
2213+
22152214
if (unlikely(!upipe_avfilt->flow_def)) {
22162215
struct uref *flow_def_attr = upipe_avfilt_alloc_flow_def_attr(upipe);
22172216
if (flow_def_attr == NULL) {
@@ -2233,8 +2232,6 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
22332232

22342233
uint64_t latency = 0;
22352234
if (frame->pts != AV_NOPTS_VALUE) {
2236-
AVRational time_base = av_buffersink_get_time_base(
2237-
upipe_avfilt->buffersink_ctx);
22382235
uint64_t pts = av_rescale_q(frame->pts, time_base,
22392236
av_make_q(1, UCLOCK_FREQ));
22402237
uint64_t input_pts;
@@ -2293,12 +2290,8 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
22932290
uint64_t pts_prog = UINT64_MAX;
22942291
uint64_t pts_sys = UINT64_MAX;
22952292
if (frame->pts != AV_NOPTS_VALUE) {
2296-
AVRational time_base = av_buffersink_get_time_base(
2297-
upipe_avfilt->buffersink_ctx);
2298-
struct urational to = { .num = UCLOCK_FREQ, .den = 1 };
2299-
struct urational from = { .num = time_base.num, .den = time_base.den };
2300-
struct urational mult = urational_multiply(&to, &from);
2301-
uint64_t pts = frame->pts * mult.num / mult.den;
2293+
uint64_t pts = av_rescale_q(frame->pts, time_base,
2294+
av_make_q(1, UCLOCK_FREQ));
23022295

23032296
if (ubase_check(uref_clock_get_pts_prog(uref, &pts_prog)) &&
23042297
ubase_check(uref_clock_get_pts_sys(uref, &pts_sys))) {
@@ -2312,7 +2305,8 @@ static void upipe_avfilt_output_frame(struct upipe *upipe,
23122305
uint64_t duration = 0;
23132306
switch (media_type) {
23142307
case AVMEDIA_TYPE_VIDEO:
2315-
duration = frame->pkt_duration;
2308+
duration = av_rescale_q(frame->pkt_duration, time_base,
2309+
av_make_q(1, UCLOCK_FREQ));
23162310

23172311
if (!frame->interlaced_frame)
23182312
UBASE_ERROR(upipe, uref_pic_set_progressive(uref))

0 commit comments

Comments
 (0)