From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
Date: Wed, 31 Jan 2024 01:05:41 +0100
Message-ID: <20240131000541.GP6420@pb2> (raw)
In-Reply-To: <20240128030136.5585-3-cus@passwd.hu>
[-- Attachment #1.1: Type: text/plain, Size: 3033 bytes --]
On Sun, Jan 28, 2024 at 04:01:36AM +0100, Marton Balint wrote:
> Yadif filter assumed that the output timebase is always half of the input
> timebase. This is not true if halving the input time base is not representable
> as an AVRational causing the output timestamps to be invalidly scaled in such a
> case.
>
> So let's use av_reduce instead of av_mul_q when calculating the output time
> base and if the conversion is inexact then let's fall back to the original
> timebase which probably makes more parctical sense than using x/INT_MAX.
>
> Fixes invalidly scaled pts_time values in this command line:
> ffmpeg -f lavfi -i testsrc -vf settb=tb=1/2000000000,yadif,showinfo -f null none
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavfilter/yadif.h | 2 ++
> libavfilter/yadif_common.c | 20 ++++++++++++++------
> 2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
> index 2c4fed62d2..c144568242 100644
> --- a/libavfilter/yadif.h
> +++ b/libavfilter/yadif.h
> @@ -86,6 +86,8 @@ typedef struct YADIFContext {
> * the first field.
> */
> int current_field; ///< YADIFCurrentField
> +
> + int pts_divisor;
> } YADIFContext;
>
> void ff_yadif_init_x86(YADIFContext *yadif);
> diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
> index 933372529e..90a5cffc2d 100644
> --- a/libavfilter/yadif_common.c
> +++ b/libavfilter/yadif_common.c
> @@ -61,7 +61,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> int64_t next_pts = yadif->next->pts;
>
> if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
> - yadif->out->pts = cur_pts + next_pts;
> + yadif->out->pts = (cur_pts + next_pts) / yadif->pts_divisor;
> } else {
> yadif->out->pts = AV_NOPTS_VALUE;
> }
> @@ -150,8 +150,8 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
> ff_ccfifo_inject(&yadif->cc_fifo, yadif->out);
> av_frame_free(&yadif->prev);
> if (yadif->out->pts != AV_NOPTS_VALUE)
> - yadif->out->pts *= 2;
> - yadif->out->duration *= 2;
> + yadif->out->pts *= 2 / yadif->pts_divisor;
> + yadif->out->duration *= 2 / yadif->pts_divisor;
> return ff_filter_frame(ctx->outputs[0], yadif->out);
> }
>
> @@ -168,9 +168,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
> yadif->out->flags &= ~AV_FRAME_FLAG_INTERLACED;
>
> if (yadif->out->pts != AV_NOPTS_VALUE)
> - yadif->out->pts *= 2;
> + yadif->out->pts *= 2 / yadif->pts_divisor;
> if (!(yadif->mode & 1))
> - yadif->out->duration *= 2;
> + yadif->out->duration *= 2 / yadif->pts_divisor;
you can use >> instead of division for all above
otherwise should be ok
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Avoid a single point of failure, be that a person or equipment.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-01-31 0:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-28 3:01 [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision Marton Balint
2024-01-28 3:01 ` [FFmpeg-devel] [PATCH 2/3] avfilter/yadif_common: factorize some part of the config_output and the uninit functions Marton Balint
2024-01-28 3:01 ` [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases Marton Balint
2024-01-31 0:05 ` Michael Niedermayer [this message]
2024-01-31 2:42 ` Marton Balint
2024-01-31 22:54 ` [FFmpeg-devel] [PATCH v2 " Marton Balint
2024-02-01 0:10 ` [FFmpeg-devel] [PATCH " Michael Niedermayer
2024-02-01 21:41 ` Marton Balint
2024-02-03 19:23 ` Marton Balint
2024-01-30 23:57 ` [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240131000541.GP6420@pb2 \
--to=michael@niedermayer.cc \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git