PR #25190 opened by Marti2203
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25190
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25190.patch

When no block has enough edge pixels, e.g. for a black or otherwise uniform 
frame, `calculate_blur()` ends with `total_width / blkcnt` where both are 0, so 
the frame is tagged `lavfi.blur=nan`, and because the value is added to 
`blur_total`, the final "blur mean" of the whole input becomes nan as well:

```
ffmpeg -f lavfi -i 
"testsrc2=s=320x240:d=0.2,trim=end_frame=3[a];color=black:s=320x240:d=0.08[b];[a][b]concat=n=2,format=yuv420p,blurdetect"
 -f null -
[Parsed_blurdetect_...] blur mean: -nan
```

Black frames at the start or end of a video are common, so one such frame makes 
the summary of an otherwise normal clip useless.

With the patch such frames report 0 (no edge width could be measured), the 
example above gives `blur mean: 2.6818365`, frames with edges are unchanged 
(e.g. 4.445965 for a testsrc2 frame), and `fate-filter-refcmp-blurdetect-yuv` 
passes. Returning 0 is one choice; excluding such frames from the mean would be 
another, happy to change it.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified 
manually.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



From f6b195d7a30f96bc23a73cf4b0e7202f6c6ef827 Mon Sep 17 00:00:00 2001
From: Martin Mirchev <[email protected]>
Date: Sun, 18 Oct 2026 22:06:08 +0800
Subject: [PATCH] avfilter/vf_blurdetect: do not divide by zero for frames
 without edges

If no block contains enough edge pixels, e.g. for a black or otherwise
uniform frame, calculate_blur() returned 0/0, so the frame got
lavfi.blur=nan and the "blur mean" of the whole input became nan as well.
Report 0 for such frames.

Signed-off-by: Martin Mirchev <[email protected]>
---
 libavfilter/vf_blurdetect.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavfilter/vf_blurdetect.c b/libavfilter/vf_blurdetect.c
index 5c6728d22f..ecdcb66591 100644
--- a/libavfilter/vf_blurdetect.c
+++ b/libavfilter/vf_blurdetect.c
@@ -236,6 +236,10 @@ static float calculate_blur(BLRContext *s, int w, int h, 
int hsub, int vsub,
     }
 
     // simple block pooling by sorting and keeping the sharper blocks
+    // no block with enough edge pixels (e.g. a uniform frame): nothing to 
measure
+    if (!blkcnt)
+        return 0;
+
     AV_QSORT(blks, blkcnt, float, comp);
     blkcnt = ceil(blkcnt * block_pool_threshold);
     for (int i = 0; i < blkcnt; i++) {
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to