[FFmpeg-cvslog] avfilter/avf_showcwt: improve range detection for morlet scales

Paul B Mahol git at videolan.org
Sun Jul 30 21:21:07 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Jul 30 19:57:50 2023 +0200| [8bbaecb5de9bac41f7e3a4179ec803ce89ac2d09] | committer: Paul B Mahol

avfilter/avf_showcwt: improve range detection for morlet scales

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8bbaecb5de9bac41f7e3a4179ec803ce89ac2d09
---

 libavfilter/avf_showcwt.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/libavfilter/avf_showcwt.c b/libavfilter/avf_showcwt.c
index 9f6265f105..8bf64cfe66 100644
--- a/libavfilter/avf_showcwt.c
+++ b/libavfilter/avf_showcwt.c
@@ -152,7 +152,7 @@ static const AVOption showcwt_options[] = {
     { "min",  "set minimum frequency", OFFSET(minimum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20.},    1, 192000, FLAGS },
     { "max",  "set maximum frequency", OFFSET(maximum_frequency), AV_OPT_TYPE_FLOAT, {.dbl = 20000.}, 1, 192000, FLAGS },
     { "logb", "set logarithmic basis", OFFSET(logarithmic_basis), AV_OPT_TYPE_FLOAT, {.dbl = 0.0001}, 0, 1, FLAGS },
-    { "deviation", "set frequency deviation", OFFSET(deviation), AV_OPT_TYPE_FLOAT, {.dbl = 1.}, 0, 10, FLAGS },
+    { "deviation", "set frequency deviation", OFFSET(deviation), AV_OPT_TYPE_FLOAT, {.dbl = 1.}, 0, 100, FLAGS },
     { "pps",  "set pixels per second", OFFSET(pps), AV_OPT_TYPE_INT, {.i64 = 64}, 1, 1024, FLAGS },
     { "mode", "set output mode", OFFSET(mode), AV_OPT_TYPE_INT,  {.i64=0}, 0, 4, FLAGS, "mode" },
     {  "magnitude", "magnitude",         0, AV_OPT_TYPE_CONST,{.i64=0}, 0, 0, FLAGS, "mode" },
@@ -701,13 +701,13 @@ static int compute_kernel(AVFilterContext *ctx)
 
     for (int y = 0; y < fsize; y++) {
         AVComplexFloat *kernel = s->kernel[y];
-        int start = 0, stop = 0;
+        int start = INT_MIN, stop = INT_MAX;
         const float frequency = s->frequency_band[y*2] * correction;
         const float deviation = 1.f / (s->frequency_band[y*2+1] *
                                        output_sample_count * correction);
-        const int range = 8.f*M_PI*sqrtf(1.f/deviation);
-        const int a = floorf(frequency-range);
-        const int b = ceilf(frequency+range);
+        const int a = FFMAX(frequency-12.f*sqrtf(1.f/deviation)-0.5f, -size);
+        const int b = FFMIN(frequency+12.f*sqrtf(1.f/deviation)-0.5f, size+a);
+        const int range = -a;
 
         memset(tkernel, 0, size * sizeof(*tkernel));
         for (int n = a; n < b; n++) {
@@ -720,7 +720,7 @@ static int compute_kernel(AVFilterContext *ctx)
         for (int n = a; n < b; n++) {
             if (tkernel[n+range] != 0.f) {
                 if (tkernel[n+range] > FLT_MIN)
-                    av_log(ctx, AV_LOG_DEBUG, "out of range kernel\n");
+                    av_log(ctx, AV_LOG_DEBUG, "out of range kernel %g\n", tkernel[n+range]);
                 start = n;
                 break;
             }
@@ -729,16 +729,21 @@ static int compute_kernel(AVFilterContext *ctx)
         for (int n = b; n >= a; n--) {
             if (tkernel[n+range] != 0.f) {
                 if (tkernel[n+range] > FLT_MIN)
-                    av_log(ctx, AV_LOG_DEBUG, "out of range kernel\n");
+                    av_log(ctx, AV_LOG_DEBUG, "out of range kernel %g\n", tkernel[n+range]);
                 stop = n;
                 break;
             }
         }
 
+        if (start == INT_MIN || stop == INT_MAX) {
+            ret = AVERROR(EINVAL);
+            break;
+        }
+
         kernel_start[y] = start;
         kernel_stop[y] = stop;
 
-        kernel = av_calloc(FFALIGN(stop - start + 1+range, 16), sizeof(*kernel));
+        kernel = av_calloc(FFALIGN(stop-start+1, 16), sizeof(*kernel));
         if (!kernel) {
             ret = AVERROR(ENOMEM);
             break;



More information about the ffmpeg-cvslog mailing list