Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision
@ 2024-01-28  3:01 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
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Marton Balint @ 2024-01-28  3:01 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

Fixes parsing small timebases from expressions (where the expression API
converts the result to double), like in this command line:

ffprobe -f lavfi -i testsrc=d=1,settb=1/2000000000 -show_streams -show_entries stream=time_base

Before the patch timebase was parsed as 1/1999999999.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/rational.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/rational.c b/libavutil/rational.c
index eb148ddb12..329fbf3302 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -114,7 +114,7 @@ AVRational av_d2q(double d, int max)
         return (AVRational) { d < 0 ? -1 : 1, 0 };
     frexp(d, &exponent);
     exponent = FFMAX(exponent-1, 0);
-    den = 1LL << (61 - exponent);
+    den = 1LL << (62 - exponent);
     // (int64_t)rint() and llrint() do not work with gcc on ia64 and sparc64,
     // see Ticket2713 for affected gcc/glibc versions
     av_reduce(&a.num, &a.den, floor(d * den + 0.5), den, max);
-- 
2.35.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH 2/3] avfilter/yadif_common: factorize some part of the config_output and the uninit functions
  2024-01-28  3:01 [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision Marton Balint
@ 2024-01-28  3:01 ` 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-30 23:57 ` [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision Michael Niedermayer
  2 siblings, 0 replies; 10+ messages in thread
From: Marton Balint @ 2024-01-28  3:01 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

This unifies slightly diverged code and ensures that cc_fifo is always initialized.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavfilter/vf_bwdif.c              | 30 +++-------------------
 libavfilter/vf_bwdif_cuda.c         | 15 +++--------
 libavfilter/vf_bwdif_vulkan.c       | 12 ++++-----
 libavfilter/vf_yadif.c              | 33 +++---------------------
 libavfilter/vf_yadif_cuda.c         | 27 +++----------------
 libavfilter/vf_yadif_videotoolbox.m | 19 +++-----------
 libavfilter/yadif.h                 |  4 +++
 libavfilter/yadif_common.c          | 40 +++++++++++++++++++++++++++++
 8 files changed, 66 insertions(+), 114 deletions(-)

diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c
index 353cd0b61a..9042db8d7f 100644
--- a/libavfilter/vf_bwdif.c
+++ b/libavfilter/vf_bwdif.c
@@ -137,17 +137,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
     }
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    BWDIFContext *bwdif = ctx->priv;
-    YADIFContext *yadif = &bwdif->yadif;
-
-    av_frame_free(&yadif->prev);
-    av_frame_free(&yadif->cur );
-    av_frame_free(&yadif->next);
-    ff_ccfifo_uninit(&yadif->cc_fifo);
-}
-
 static const enum AVPixelFormat pix_fmts[] = {
     AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P,
     AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
@@ -176,20 +165,9 @@ static int config_props(AVFilterLink *link)
     YADIFContext *yadif = &s->yadif;
     int ret;
 
-    link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
-    link->w         = link->src->inputs[0]->w;
-    link->h         = link->src->inputs[0]->h;
-
-    if(yadif->mode&1)
-        link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1});
-    else
-        link->frame_rate = ctx->inputs[0]->frame_rate;
-
-    ret = ff_ccfifo_init(&yadif->cc_fifo, link->frame_rate, ctx);
-    if (ret < 0 ) {
-        av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
-        return ret;
-    }
+    ret = ff_yadif_config_output_common(link);
+    if (ret < 0)
+        return AVERROR(EINVAL);
 
     yadif->csp = av_pix_fmt_desc_get(link->format);
     yadif->filter = filter;
@@ -251,7 +229,7 @@ const AVFilter ff_vf_bwdif = {
     .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
     .priv_size     = sizeof(BWDIFContext),
     .priv_class    = &bwdif_class,
-    .uninit        = uninit,
+    .uninit        = ff_yadif_uninit,
     FILTER_INPUTS(avfilter_vf_bwdif_inputs),
     FILTER_OUTPUTS(avfilter_vf_bwdif_outputs),
     FILTER_PIXFMTS_ARRAY(pix_fmts),
diff --git a/libavfilter/vf_bwdif_cuda.c b/libavfilter/vf_bwdif_cuda.c
index 418f15f989..7585d1fe25 100644
--- a/libavfilter/vf_bwdif_cuda.c
+++ b/libavfilter/vf_bwdif_cuda.c
@@ -208,9 +208,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
         CHECK_CU(cu->cuCtxPopCurrent(&dummy));
     }
 
-    av_frame_free(&y->prev);
-    av_frame_free(&y->cur);
-    av_frame_free(&y->next);
+    ff_yadif_uninit(ctx);
 
     av_buffer_unref(&s->device_ref);
     s->hwctx = NULL;
@@ -288,14 +286,9 @@ static int config_output(AVFilterLink *link)
         goto exit;
     }
 
-    link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
-    link->w         = ctx->inputs[0]->w;
-    link->h         = ctx->inputs[0]->h;
-
-    if(y->mode & 1)
-        link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
-                                    (AVRational){2, 1});
-
+    ret = ff_yadif_config_output_common(link);
+    if (ret < 0)
+        goto exit;
 
     y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
     y->filter = filter;
diff --git a/libavfilter/vf_bwdif_vulkan.c b/libavfilter/vf_bwdif_vulkan.c
index c51df9aa26..57711fb672 100644
--- a/libavfilter/vf_bwdif_vulkan.c
+++ b/libavfilter/vf_bwdif_vulkan.c
@@ -296,6 +296,8 @@ static void bwdif_vulkan_uninit(AVFilterContext *avctx)
 
     ff_vk_uninit(&s->vkctx);
 
+    ff_yadif_uninit(avctx);
+
     s->initialized = 0;
 }
 
@@ -354,13 +356,9 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink)
     if (!outlink->hw_frames_ctx)
         return AVERROR(ENOMEM);
 
-    outlink->time_base = av_mul_q(avctx->inputs[0]->time_base, (AVRational){1, 2});
-    outlink->w         = vkctx->output_width;
-    outlink->h         = vkctx->output_height;
-
-    if (y->mode & 1)
-        outlink->frame_rate = av_mul_q(avctx->inputs[0]->frame_rate,
-                                       (AVRational){2, 1});
+    err = ff_yadif_config_output_common(outlink);
+    if (err < 0)
+        return err;
 
     y->csp = av_pix_fmt_desc_get(vkctx->frames->sw_format);
     y->filter = bwdif_vulkan_filter_frame;
diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index a5a856bf5f..aa5ca4a889 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -251,16 +251,6 @@ static void filter(AVFilterContext *ctx, AVFrame *dstpic,
     }
 }
 
-static av_cold void uninit(AVFilterContext *ctx)
-{
-    YADIFContext *yadif = ctx->priv;
-
-    av_frame_free(&yadif->prev);
-    av_frame_free(&yadif->cur );
-    av_frame_free(&yadif->next);
-    ff_ccfifo_uninit(&yadif->cc_fifo);
-}
-
 static const enum AVPixelFormat pix_fmts[] = {
     AV_PIX_FMT_YUV420P,   AV_PIX_FMT_YUV422P,   AV_PIX_FMT_YUV444P,
     AV_PIX_FMT_YUV410P,   AV_PIX_FMT_YUV411P,   AV_PIX_FMT_YUV440P,
@@ -285,26 +275,9 @@ static int config_output(AVFilterLink *outlink)
     YADIFContext *s = ctx->priv;
     int ret;
 
-    outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
-    outlink->w             = ctx->inputs[0]->w;
-    outlink->h             = ctx->inputs[0]->h;
-
-    if(s->mode & 1)
-        outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
-                                    (AVRational){2, 1});
-    else
-        outlink->frame_rate = ctx->inputs[0]->frame_rate;
-
-    ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx);
-    if (ret < 0) {
-        av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
+    ret = ff_yadif_config_output_common(outlink);
+    if (ret < 0)
         return ret;
-    }
-
-    if (outlink->w < 3 || outlink->h < 3) {
-        av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
-        return AVERROR(EINVAL);
-    }
 
     s->csp = av_pix_fmt_desc_get(outlink->format);
     s->filter = filter;
@@ -354,7 +327,7 @@ const AVFilter ff_vf_yadif = {
     .description   = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
     .priv_size     = sizeof(YADIFContext),
     .priv_class    = &yadif_class,
-    .uninit        = uninit,
+    .uninit        = ff_yadif_uninit,
     FILTER_INPUTS(avfilter_vf_yadif_inputs),
     FILTER_OUTPUTS(avfilter_vf_yadif_outputs),
     FILTER_PIXFMTS_ARRAY(pix_fmts),
diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c
index d777757e65..17389f092f 100644
--- a/libavfilter/vf_yadif_cuda.c
+++ b/libavfilter/vf_yadif_cuda.c
@@ -200,10 +200,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
         CHECK_CU(cu->cuCtxPopCurrent(&dummy));
     }
 
-    av_frame_free(&y->prev);
-    av_frame_free(&y->cur);
-    av_frame_free(&y->next);
-    ff_ccfifo_uninit(&y->cc_fifo);
+    ff_yadif_uninit(ctx);
 
     av_buffer_unref(&s->device_ref);
     s->hwctx = NULL;
@@ -281,27 +278,9 @@ static int config_output(AVFilterLink *link)
         goto exit;
     }
 
-    link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
-    link->w         = ctx->inputs[0]->w;
-    link->h         = ctx->inputs[0]->h;
-
-    if(y->mode & 1)
-        link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
-                                    (AVRational){2, 1});
-    else
-        link->frame_rate = ctx->inputs[0]->frame_rate;
-
-    ret = ff_ccfifo_init(&y->cc_fifo, link->frame_rate, ctx);
-    if (ret < 0) {
-        av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
-        goto exit;
-    }
-
-    if (link->w < 3 || link->h < 3) {
-        av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
-        ret = AVERROR(EINVAL);
+    ret = ff_yadif_config_output_common(link);
+    if (ret < 0)
         goto exit;
-    }
 
     y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
     y->filter = filter;
diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m
index 69186c2254..28d836b782 100644
--- a/libavfilter/vf_yadif_videotoolbox.m
+++ b/libavfilter/vf_yadif_videotoolbox.m
@@ -174,9 +174,7 @@ static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11),
     YADIFVTContext *s = ctx->priv;
     YADIFContext *y = &s->yadif;
 
-    av_frame_free(&y->prev);
-    av_frame_free(&y->cur);
-    av_frame_free(&y->next);
+    ff_yadif_uninit(ctx);
 
     av_buffer_unref(&s->device_ref);
     av_buffer_unref(&s->input_frames_ref);
@@ -363,20 +361,9 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(
         goto exit;
     }
 
-    link->time_base.num = ctx->inputs[0]->time_base.num;
-    link->time_base.den = ctx->inputs[0]->time_base.den * 2;
-    link->w             = ctx->inputs[0]->w;
-    link->h             = ctx->inputs[0]->h;
-
-    if(y->mode & 1)
-        link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
-                                    (AVRational){2, 1});
-
-    if (link->w < 3 || link->h < 3) {
-        av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
-        ret = AVERROR(EINVAL);
+    ret = ff_yadif_config_output_common(link);
+    if (ret < 0)
         goto exit;
-    }
 
     y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
     y->filter = filter;
diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index fbb99fd46e..2c4fed62d2 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -94,6 +94,10 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame);
 
 int ff_yadif_request_frame(AVFilterLink *link);
 
+int ff_yadif_config_output_common(AVFilterLink *outlink);
+
+void ff_yadif_uninit(AVFilterContext *ctx);
+
 extern const AVOption ff_yadif_options[];
 
 #endif /* AVFILTER_YADIF_H */
diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
index 21097011f5..933372529e 100644
--- a/libavfilter/yadif_common.c
+++ b/libavfilter/yadif_common.c
@@ -209,6 +209,46 @@ int ff_yadif_request_frame(AVFilterLink *link)
     return 0;
 }
 
+int ff_yadif_config_output_common(AVFilterLink *outlink)
+{
+    AVFilterContext *ctx = outlink->src;
+    YADIFContext *yadif = ctx->priv;
+    int ret;
+
+    outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
+    outlink->w             = ctx->inputs[0]->w;
+    outlink->h             = ctx->inputs[0]->h;
+
+    if (outlink->w < 3 || outlink->h < 3) {
+        av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
+        return AVERROR(EINVAL);
+    }
+
+    if(yadif->mode & 1)
+        outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
+                                    (AVRational){2, 1});
+    else
+        outlink->frame_rate = ctx->inputs[0]->frame_rate;
+
+    ret = ff_ccfifo_init(&yadif->cc_fifo, outlink->frame_rate, ctx);
+    if (ret < 0) {
+        av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n");
+        return ret;
+    }
+
+    return 0;
+}
+
+void ff_yadif_uninit(AVFilterContext *ctx)
+{
+    YADIFContext *yadif = ctx->priv;
+
+    av_frame_free(&yadif->prev);
+    av_frame_free(&yadif->cur );
+    av_frame_free(&yadif->next);
+    ff_ccfifo_uninit(&yadif->cc_fifo);
+}
+
 #define OFFSET(x) offsetof(YADIFContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
-- 
2.35.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  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 ` Marton Balint
  2024-01-31  0:05   ` Michael Niedermayer
  2024-01-30 23:57 ` [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision Michael Niedermayer
  2 siblings, 1 reply; 10+ messages in thread
From: Marton Balint @ 2024-01-28  3:01 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

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;
 
     return return_frame(ctx, 0);
 }
@@ -213,9 +213,17 @@ int ff_yadif_config_output_common(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     YADIFContext *yadif = ctx->priv;
+    AVRational tb = ctx->inputs[0]->time_base;
     int ret;
 
-    outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
+    if (av_reduce(&outlink->time_base.num, &outlink->time_base.den, tb.num, tb.den * 2LL, INT_MAX)) {
+        yadif->pts_divisor = 1;
+    } else {
+        av_log(ctx, AV_LOG_WARNING, "Cannot use exact output timebase\n");
+        outlink->time_base = tb;
+        yadif->pts_divisor = 2;
+    }
+
     outlink->w             = ctx->inputs[0]->w;
     outlink->h             = ctx->inputs[0]->h;
 
-- 
2.35.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/3] avutil/rational: increase av_d2q precision
  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-30 23:57 ` Michael Niedermayer
  2 siblings, 0 replies; 10+ messages in thread
From: Michael Niedermayer @ 2024-01-30 23:57 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 793 bytes --]

On Sun, Jan 28, 2024 at 04:01:34AM +0100, Marton Balint wrote:
> Fixes parsing small timebases from expressions (where the expression API
> converts the result to double), like in this command line:
> 
> ffprobe -f lavfi -i testsrc=d=1,settb=1/2000000000 -show_streams -show_entries stream=time_base
> 
> Before the patch timebase was parsed as 1/1999999999.
> 
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavutil/rational.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

should be ok

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Homeopathy is like voting while filling the ballot out with transparent ink.
Sometimes the outcome one wanted occurs. Rarely its worse than filling out
a ballot properly.

[-- 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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  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
  2024-01-31  2:42     ` Marton Balint
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Niedermayer @ 2024-01-31  0:05 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- 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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  2024-01-31  0:05   ` Michael Niedermayer
@ 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
  0 siblings, 2 replies; 10+ messages in thread
From: Marton Balint @ 2024-01-31  2:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Wed, 31 Jan 2024, Michael Niedermayer wrote:

> 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

Even for the first case? Because the right shift would be implementation 
defined for negative timestamps.

Thanks,
Marton
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH v2 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  2024-01-31  2:42     ` Marton Balint
@ 2024-01-31 22:54       ` Marton Balint
  2024-02-01  0:10       ` [FFmpeg-devel] [PATCH " Michael Niedermayer
  1 sibling, 0 replies; 10+ messages in thread
From: Marton Balint @ 2024-01-31 22:54 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

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

v2: use less divisons and fix durations

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavfilter/yadif.h        |  2 ++
 libavfilter/yadif_common.c | 24 +++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 2c4fed62d2..888ba12365 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_multiplier;
 } YADIFContext;
 
 void ff_yadif_init_x86(YADIFContext *yadif);
diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c
index 933372529e..446ffb7c3d 100644
--- a/libavfilter/yadif_common.c
+++ b/libavfilter/yadif_common.c
@@ -62,6 +62,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
         if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
             yadif->out->pts = cur_pts + next_pts;
+            if (yadif->pts_multiplier == 1) {
+                yadif->out->pts /= 2;
+                yadif->out->duration /= 2;
+            }
         } else {
             yadif->out->pts = AV_NOPTS_VALUE;
         }
@@ -150,8 +154,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 *= yadif->pts_multiplier;
+        yadif->out->duration *= yadif->pts_multiplier;
         return ff_filter_frame(ctx->outputs[0], yadif->out);
     }
 
@@ -168,9 +172,11 @@ 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 *= yadif->pts_multiplier;
     if (!(yadif->mode & 1))
-        yadif->out->duration *= 2;
+        yadif->out->duration *= yadif->pts_multiplier;
+    else if (yadif->pts_multiplier == 1)
+        yadif->out->duration /= 2;
 
     return return_frame(ctx, 0);
 }
@@ -213,9 +219,17 @@ int ff_yadif_config_output_common(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     YADIFContext *yadif = ctx->priv;
+    AVRational tb = ctx->inputs[0]->time_base;
     int ret;
 
-    outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
+    if (av_reduce(&outlink->time_base.num, &outlink->time_base.den, tb.num, tb.den * 2LL, INT_MAX)) {
+        yadif->pts_multiplier = 2;
+    } else {
+        av_log(ctx, AV_LOG_WARNING, "Cannot use exact output timebase\n");
+        outlink->time_base = tb;
+        yadif->pts_multiplier = 1;
+    }
+
     outlink->w             = ctx->inputs[0]->w;
     outlink->h             = ctx->inputs[0]->h;
 
-- 
2.35.3

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  2024-01-31  2:42     ` Marton Balint
  2024-01-31 22:54       ` [FFmpeg-devel] [PATCH v2 " Marton Balint
@ 2024-02-01  0:10       ` Michael Niedermayer
  2024-02-01 21:41         ` Marton Balint
  1 sibling, 1 reply; 10+ messages in thread
From: Michael Niedermayer @ 2024-02-01  0:10 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 3732 bytes --]

On Wed, Jan 31, 2024 at 03:42:46AM +0100, Marton Balint wrote:
> 
> 
> On Wed, 31 Jan 2024, Michael Niedermayer wrote:
> 
> > 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
> 
> Even for the first case? Because the right shift would be implementation
> defined for negative timestamps.

we are only supporting twos-complement systems
i thought that was somewhete in teh docs

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras

[-- 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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  2024-02-01  0:10       ` [FFmpeg-devel] [PATCH " Michael Niedermayer
@ 2024-02-01 21:41         ` Marton Balint
  2024-02-03 19:23           ` Marton Balint
  0 siblings, 1 reply; 10+ messages in thread
From: Marton Balint @ 2024-02-01 21:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


On Thu, 1 Feb 2024, Michael Niedermayer wrote:

> On Wed, Jan 31, 2024 at 03:42:46AM +0100, Marton Balint wrote:
>>
>>
>> On Wed, 31 Jan 2024, Michael Niedermayer wrote:
>>
>>> 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
>>
>> Even for the first case? Because the right shift would be implementation
>> defined for negative timestamps.
>
> we are only supporting twos-complement systems
> i thought that was somewhete in teh docs

Ok, I will change the /= 2 divisions to >>= 1 shifts in v2 patch then.

Thanks,
Marton
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 3/3] avfilter/yadif_common: fix timestamps with very small timebases
  2024-02-01 21:41         ` Marton Balint
@ 2024-02-03 19:23           ` Marton Balint
  0 siblings, 0 replies; 10+ messages in thread
From: Marton Balint @ 2024-02-03 19:23 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Thu, 1 Feb 2024, Marton Balint wrote:

>
> On Thu, 1 Feb 2024, Michael Niedermayer wrote:
>
>>  On Wed, Jan 31, 2024 at 03:42:46AM +0100, Marton Balint wrote:
>>> 
>>>
>>>  On Wed, 31 Jan 2024, Michael Niedermayer wrote:
>>>
>>>>  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
>>>
>>>  Even for the first case? Because the right shift would be implementation
>>>  defined for negative timestamps.
>>
>>  we are only supporting twos-complement systems
>>  i thought that was somewhete in teh docs
>
> Ok, I will change the /= 2 divisions to >>= 1 shifts in v2 patch then.

Will apply the series.

Regards,
Marton
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-02-03 19:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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