diff mbox series

[FFmpeg-devel,1/2] avfilter/vf_gblur: fix divide by zero

Message ID 20200104102316.80671-1-quinkblack@foxmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avfilter/vf_gblur: fix divide by zero
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

zhilizhao Jan. 4, 2020, 10:23 a.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
...
src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
---
 libavfilter/vf_gblur.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Paul B Mahol Jan. 4, 2020, 11:04 a.m. UTC | #1
I do not like this "fix"

On 1/4/20, quinkblack@foxmail.com <quinkblack@foxmail.com> wrote:
> From: Zhao Zhili <zhilizhao@tencent.com>
>
> ./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
> ...
> src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
> src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
> ---
>  libavfilter/vf_gblur.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
> index 2e587f6a0a..e057937fb7 100644
> --- a/libavfilter/vf_gblur.c
> +++ b/libavfilter/vf_gblur.c
> @@ -37,11 +37,17 @@
>  #define OFFSET(x) offsetof(GBlurContext, x)
>  #define FLAGS
> AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
>
> +/* Consider the three-sigma rule, for minimum radius of 1 sigma should not
> + * be smaller than 1/3. Relax it to 0.25 if the user want to try.
> + */
> +#define SIGMA_MIN   0.25
> +#define SIGMA_MAX   1024.0
> +
>  static const AVOption gblur_options[] = {
> -    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT,
> {.dbl=0.5}, 0.0, 1024, FLAGS },
> +    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT,
> {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
>      { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,
> {.i64=1},     1,    6, FLAGS },
>      { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,
> {.i64=0xF},   0,  0xF, FLAGS },
> -    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT,
> {.dbl=-1},   -1, 1024, FLAGS },
> +    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT,
> {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
>      { NULL }
>  };
>
> @@ -244,7 +250,7 @@ static int config_input(AVFilterLink *inlink)
>      if (!s->buffer)
>          return AVERROR(ENOMEM);
>
> -    if (s->sigmaV < 0) {
> +    if (s->sigmaV < SIGMA_MIN) {
>          s->sigmaV = s->sigma;
>      }
>      ff_gblur_init(s);
> --
> 2.22.0
>
> _______________________________________________
> 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".
zhilizhao Jan. 4, 2020, 12:56 p.m. UTC | #2
> On Jan 4, 2020, at 7:04 PM, Paul B Mahol <onemda@gmail.com> wrote:
> 
> I do not like this “fix"

What do you suggest?  It’s numerical unstable for small sigma.

> 
> On 1/4/20, quinkblack@foxmail.com <quinkblack@foxmail.com> wrote:
>> From: Zhao Zhili <zhilizhao@tencent.com>
>> 
>> ./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
>> ...
>> src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
>> src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
>> ---
>> libavfilter/vf_gblur.c | 12 +++++++++---
>> 1 file changed, 9 insertions(+), 3 deletions(-)
>> 
>> diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
>> index 2e587f6a0a..e057937fb7 100644
>> --- a/libavfilter/vf_gblur.c
>> +++ b/libavfilter/vf_gblur.c
>> @@ -37,11 +37,17 @@
>> #define OFFSET(x) offsetof(GBlurContext, x)
>> #define FLAGS
>> AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
>> 
>> +/* Consider the three-sigma rule, for minimum radius of 1 sigma should not
>> + * be smaller than 1/3. Relax it to 0.25 if the user want to try.
>> + */
>> +#define SIGMA_MIN   0.25
>> +#define SIGMA_MAX   1024.0
>> +
>> static const AVOption gblur_options[] = {
>> -    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT,
>> {.dbl=0.5}, 0.0, 1024, FLAGS },
>> +    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT,
>> {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
>>     { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,
>> {.i64=1},     1,    6, FLAGS },
>>     { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,
>> {.i64=0xF},   0,  0xF, FLAGS },
>> -    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT,
>> {.dbl=-1},   -1, 1024, FLAGS },
>> +    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT,
>> {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
>>     { NULL }
>> };
>> 
>> @@ -244,7 +250,7 @@ static int config_input(AVFilterLink *inlink)
>>     if (!s->buffer)
>>         return AVERROR(ENOMEM);
>> 
>> -    if (s->sigmaV < 0) {
>> +    if (s->sigmaV < SIGMA_MIN) {
>>         s->sigmaV = s->sigma;
>>     }
>>     ff_gblur_init(s);
>> --
>> 2.22.0
>> 
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
Paul B Mahol Jan. 4, 2020, 1:09 p.m. UTC | #3
On 1/4/20, zhilizhao <quinkblack@foxmail.com> wrote:
>
>
>> On Jan 4, 2020, at 7:04 PM, Paul B Mahol <onemda@gmail.com> wrote:
>>
>> I do not like this “fix"
>
> What do you suggest?  It’s numerical unstable for small sigma.

For small sigma return frames unchanged as it currently does.

>
>>
>> On 1/4/20, quinkblack@foxmail.com <quinkblack@foxmail.com> wrote:
>>> From: Zhao Zhili <zhilizhao@tencent.com>
>>>
>>> ./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
>>> ...
>>> src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
>>> src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
>>> ---
>>> libavfilter/vf_gblur.c | 12 +++++++++---
>>> 1 file changed, 9 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
>>> index 2e587f6a0a..e057937fb7 100644
>>> --- a/libavfilter/vf_gblur.c
>>> +++ b/libavfilter/vf_gblur.c
>>> @@ -37,11 +37,17 @@
>>> #define OFFSET(x) offsetof(GBlurContext, x)
>>> #define FLAGS
>>> AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
>>>
>>> +/* Consider the three-sigma rule, for minimum radius of 1 sigma should
>>> not
>>> + * be smaller than 1/3. Relax it to 0.25 if the user want to try.
>>> + */
>>> +#define SIGMA_MIN   0.25
>>> +#define SIGMA_MAX   1024.0
>>> +
>>> static const AVOption gblur_options[] = {
>>> -    { "sigma",  "set sigma",            OFFSET(sigma),
>>> AV_OPT_TYPE_FLOAT,
>>> {.dbl=0.5}, 0.0, 1024, FLAGS },
>>> +    { "sigma",  "set sigma",            OFFSET(sigma),
>>> AV_OPT_TYPE_FLOAT,
>>> {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
>>>     { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,
>>> {.i64=1},     1,    6, FLAGS },
>>>     { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,
>>> {.i64=0xF},   0,  0xF, FLAGS },
>>> -    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>> AV_OPT_TYPE_FLOAT,
>>> {.dbl=-1},   -1, 1024, FLAGS },
>>> +    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>> AV_OPT_TYPE_FLOAT,
>>> {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
>>>     { NULL }
>>> };
>>>
>>> @@ -244,7 +250,7 @@ static int config_input(AVFilterLink *inlink)
>>>     if (!s->buffer)
>>>         return AVERROR(ENOMEM);
>>>
>>> -    if (s->sigmaV < 0) {
>>> +    if (s->sigmaV < SIGMA_MIN) {
>>>         s->sigmaV = s->sigma;
>>>     }
>>>     ff_gblur_init(s);
>>> --
>>> 2.22.0
>>>
>>> _______________________________________________
>>> 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".
>> _______________________________________________
>> 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".
>
>
>
> _______________________________________________
> 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".
zhilizhao Jan. 4, 2020, 1:43 p.m. UTC | #4
> On Jan 4, 2020, at 9:09 PM, Paul B Mahol <onemda@gmail.com> wrote:
> 
> On 1/4/20, zhilizhao <quinkblack@foxmail.com> wrote:
>> 
>> 
>>> On Jan 4, 2020, at 7:04 PM, Paul B Mahol <onemda@gmail.com> wrote:
>>> 
>>> I do not like this “fix"
>> 
>> What do you suggest?  It’s numerical unstable for small sigma.
> 
> For small sigma return frames unchanged as it currently does.

Then which valud should be selected as the threshold:

1. A value from which it becomes unstable (it’s not fun to figure it out).

2. A reasonable (and random) selected value like 0.25


> 
>> 
>>> 
>>> On 1/4/20, quinkblack@foxmail.com <quinkblack@foxmail.com> wrote:
>>>> From: Zhao Zhili <zhilizhao@tencent.com>
>>>> 
>>>> ./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
>>>> ...
>>>> src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
>>>> src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
>>>> ---
>>>> libavfilter/vf_gblur.c | 12 +++++++++---
>>>> 1 file changed, 9 insertions(+), 3 deletions(-)
>>>> 
>>>> diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
>>>> index 2e587f6a0a..e057937fb7 100644
>>>> --- a/libavfilter/vf_gblur.c
>>>> +++ b/libavfilter/vf_gblur.c
>>>> @@ -37,11 +37,17 @@
>>>> #define OFFSET(x) offsetof(GBlurContext, x)
>>>> #define FLAGS
>>>> AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
>>>> 
>>>> +/* Consider the three-sigma rule, for minimum radius of 1 sigma should
>>>> not
>>>> + * be smaller than 1/3. Relax it to 0.25 if the user want to try.
>>>> + */
>>>> +#define SIGMA_MIN   0.25
>>>> +#define SIGMA_MAX   1024.0
>>>> +
>>>> static const AVOption gblur_options[] = {
>>>> -    { "sigma",  "set sigma",            OFFSET(sigma),
>>>> AV_OPT_TYPE_FLOAT,
>>>> {.dbl=0.5}, 0.0, 1024, FLAGS },
>>>> +    { "sigma",  "set sigma",            OFFSET(sigma),
>>>> AV_OPT_TYPE_FLOAT,
>>>> {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
>>>>    { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,
>>>> {.i64=1},     1,    6, FLAGS },
>>>>    { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,
>>>> {.i64=0xF},   0,  0xF, FLAGS },
>>>> -    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>>> AV_OPT_TYPE_FLOAT,
>>>> {.dbl=-1},   -1, 1024, FLAGS },
>>>> +    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>>> AV_OPT_TYPE_FLOAT,
>>>> {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
>>>>    { NULL }
>>>> };
>>>> 
>>>> @@ -244,7 +250,7 @@ static int config_input(AVFilterLink *inlink)
>>>>    if (!s->buffer)
>>>>        return AVERROR(ENOMEM);
>>>> 
>>>> -    if (s->sigmaV < 0) {
>>>> +    if (s->sigmaV < SIGMA_MIN) {
>>>>        s->sigmaV = s->sigma;
>>>>    }
>>>>    ff_gblur_init(s);
>>>> --
>>>> 2.22.0
>>>> 
>>>> _______________________________________________
>>>> 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".
>>> _______________________________________________
>>> 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".
>> 
>> 
>> 
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
zhilizhao Jan. 6, 2020, 5:11 a.m. UTC | #5
> On Jan 4, 2020, at 9:43 PM, zhilizhao <quinkblack@foxmail.com> wrote:
> 
> 
> 
>> On Jan 4, 2020, at 9:09 PM, Paul B Mahol <onemda@gmail.com <mailto:onemda@gmail.com>> wrote:
>> 
>> On 1/4/20, zhilizhao <quinkblack@foxmail.com <mailto:quinkblack@foxmail.com>> wrote:
>>> 
>>> 
>>>> On Jan 4, 2020, at 7:04 PM, Paul B Mahol <onemda@gmail.com <mailto:onemda@gmail.com>> wrote:
>>>> 
>>>> I do not like this “fix"
>>> 
>>> What do you suggest?  It’s numerical unstable for small sigma.
>> 
>> For small sigma return frames unchanged as it currently does.
> 
> Then which valud should be selected as the threshold:
> 
> 1. A value from which it becomes unstable (it’s not fun to figure it out).
> 
> 2. A reasonable (and random) selected value like 0.25
> 

For function set_params:

static void set_params(float sigma, int steps, float *postscale, float *boundaryscale, float *nu)
{
    double dnu, lambda;

    lambda = (sigma * sigma) / (2.0 * steps);
    dnu = (1.0 + 2.0 * lambda - sqrt(1.0 + 4.0 * lambda)) / (2.0 * lambda);
    *postscale = pow(dnu / lambda, steps);
    *boundaryscale = 1.0 / (1.0 - dnu);
    *nu = (float)dnu;
}

1. Check sigma against 0 is not enough, since lambda can be 0 for non-zero sigma
2. Check lambda against 0 is not enough, we should avoid dividing by small value, like 'dnu / lambda’.

So there should have a dead-zone for sigma.

> 
>> 
>>> 
>>>> 
>>>> On 1/4/20, quinkblack@foxmail.com <quinkblack@foxmail.com> wrote:
>>>>> From: Zhao Zhili <zhilizhao@tencent.com>
>>>>> 
>>>>> ./ffmpeg -i ~/Pictures/test.jpg -vf 'gblur=sigma=0' -f null -
>>>>> ...
>>>>> src/libavfilter/vf_gblur.c:260:59: runtime error: division by zero
>>>>> src/libavfilter/vf_gblur.c:261:26: runtime error: division by zero
>>>>> ---
>>>>> libavfilter/vf_gblur.c | 12 +++++++++---
>>>>> 1 file changed, 9 insertions(+), 3 deletions(-)
>>>>> 
>>>>> diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
>>>>> index 2e587f6a0a..e057937fb7 100644
>>>>> --- a/libavfilter/vf_gblur.c
>>>>> +++ b/libavfilter/vf_gblur.c
>>>>> @@ -37,11 +37,17 @@
>>>>> #define OFFSET(x) offsetof(GBlurContext, x)
>>>>> #define FLAGS
>>>>> AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
>>>>> 
>>>>> +/* Consider the three-sigma rule, for minimum radius of 1 sigma should
>>>>> not
>>>>> + * be smaller than 1/3. Relax it to 0.25 if the user want to try.
>>>>> + */
>>>>> +#define SIGMA_MIN   0.25
>>>>> +#define SIGMA_MAX   1024.0
>>>>> +
>>>>> static const AVOption gblur_options[] = {
>>>>> -    { "sigma",  "set sigma",            OFFSET(sigma),
>>>>> AV_OPT_TYPE_FLOAT,
>>>>> {.dbl=0.5}, 0.0, 1024, FLAGS },
>>>>> +    { "sigma",  "set sigma",            OFFSET(sigma),
>>>>> AV_OPT_TYPE_FLOAT,
>>>>> {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
>>>>>   { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,
>>>>> {.i64=1},     1,    6, FLAGS },
>>>>>   { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,
>>>>> {.i64=0xF},   0,  0xF, FLAGS },
>>>>> -    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>>>> AV_OPT_TYPE_FLOAT,
>>>>> {.dbl=-1},   -1, 1024, FLAGS },
>>>>> +    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV),
>>>>> AV_OPT_TYPE_FLOAT,
>>>>> {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
>>>>>   { NULL }
>>>>> };
>>>>> 
>>>>> @@ -244,7 +250,7 @@ static int config_input(AVFilterLink *inlink)
>>>>>   if (!s->buffer)
>>>>>       return AVERROR(ENOMEM);
>>>>> 
>>>>> -    if (s->sigmaV < 0) {
>>>>> +    if (s->sigmaV < SIGMA_MIN) {
>>>>>       s->sigmaV = s->sigma;
>>>>>   }
>>>>>   ff_gblur_init(s);
>>>>> --
>>>>> 2.22.0
>>>>> 
>>>>> _______________________________________________
>>>>> 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".
>>>> _______________________________________________
>>>> 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".
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> 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".
>> _______________________________________________
>> 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".
> 
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/vf_gblur.c b/libavfilter/vf_gblur.c
index 2e587f6a0a..e057937fb7 100644
--- a/libavfilter/vf_gblur.c
+++ b/libavfilter/vf_gblur.c
@@ -37,11 +37,17 @@ 
 #define OFFSET(x) offsetof(GBlurContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
+/* Consider the three-sigma rule, for minimum radius of 1 sigma should not
+ * be smaller than 1/3. Relax it to 0.25 if the user want to try.
+ */
+#define SIGMA_MIN   0.25
+#define SIGMA_MAX   1024.0
+
 static const AVOption gblur_options[] = {
-    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.0, 1024, FLAGS },
+    { "sigma",  "set sigma",            OFFSET(sigma),  AV_OPT_TYPE_FLOAT, {.dbl=0.5},  SIGMA_MIN, SIGMA_MAX, FLAGS },
     { "steps",  "set number of steps",  OFFSET(steps),  AV_OPT_TYPE_INT,   {.i64=1},     1,    6, FLAGS },
     { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT,   {.i64=0xF},   0,  0xF, FLAGS },
-    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT, {.dbl=-1},   -1, 1024, FLAGS },
+    { "sigmaV", "set vertical sigma",   OFFSET(sigmaV), AV_OPT_TYPE_FLOAT, {.dbl=-1},   -1, SIGMA_MAX, FLAGS },
     { NULL }
 };
 
@@ -244,7 +250,7 @@  static int config_input(AVFilterLink *inlink)
     if (!s->buffer)
         return AVERROR(ENOMEM);
 
-    if (s->sigmaV < 0) {
+    if (s->sigmaV < SIGMA_MIN) {
         s->sigmaV = s->sigma;
     }
     ff_gblur_init(s);