[FFmpeg-devel] Patch proposal : Fix crash with astats filter when no audio input
Nicolas George
george at nsup.org
Sun Mar 8 00:07:21 CET 2015
Le septidi 17 ventôse, an CCXXIII, Martin Vignali a écrit :
> Exemple to create the crash :
> ffmpeg -i fileWithoutSound -filter astats -f null -
I experience no crash. As far as I can see, the divisions happen with
floats, which is valid.
> From 621b18a278c3d314da773b8eec9f9e12707a20bb Mon Sep 17 00:00:00 2001
> From: Martin Vignali <martin.vignali at gmail.com>
> Date: Sat, 7 Mar 2015 23:09:40 +0100
> Subject: [PATCH] Fix crash in astats filter, whith no audio input
>
> Avoid Zero division in print part.
> ---
> libavfilter/af_astats.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
> index 60ccd73..8e90f6b 100644
> --- a/libavfilter/af_astats.c
> +++ b/libavfilter/af_astats.c
> @@ -222,18 +222,20 @@ static void print_stats(AVFilterContext *ctx)
> av_log(ctx, AV_LOG_INFO, "Peak count: %"PRId64"\n", p->min_count + p->max_count);
> }
>
> - av_log(ctx, AV_LOG_INFO, "Overall\n");
> - av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels));
> - av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min);
> - av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max);
> - av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-min, max)));
> - av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
> - av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));
Please do the reindent in a separate patch.
> - if (min_sigma_x2 != 1)
> + if ((s->nb_channels != 0)&&(nb_samples !=0)){/* Avoid crash when input don't have sound */
s->nb_channels can not be 0.
And cosmetic nit: the standard coding style in FFmpeg is: no "!= 0", no
extra parentheses on tests, spaces around operators, including &&, and
between clause and braces.
> + av_log(ctx, AV_LOG_INFO, "Overall\n");
> + av_log(ctx, AV_LOG_INFO, "DC offset: %f\n", max_sigma_x / (nb_samples / s->nb_channels));
> + av_log(ctx, AV_LOG_INFO, "Min level: %f\n", min);
> + av_log(ctx, AV_LOG_INFO, "Max level: %f\n", max);
> + av_log(ctx, AV_LOG_INFO, "Peak level dB: %f\n", LINEAR_TO_DB(FFMAX(-min, max)));
> + av_log(ctx, AV_LOG_INFO, "RMS level dB: %f\n", LINEAR_TO_DB(sqrt(sigma_x2 / nb_samples)));
> + av_log(ctx, AV_LOG_INFO, "RMS peak dB: %f\n", LINEAR_TO_DB(sqrt(max_sigma_x2)));
> + if (min_sigma_x2 != 1)
> av_log(ctx, AV_LOG_INFO, "RMS trough dB: %f\n", LINEAR_TO_DB(sqrt(min_sigma_x2)));
> - av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
> - av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
> - av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
> + av_log(ctx, AV_LOG_INFO, "Flat factor: %f\n", LINEAR_TO_DB((min_runs + max_runs) / (min_count + max_count)));
> + av_log(ctx, AV_LOG_INFO, "Peak count: %f\n", (min_count + max_count) / (double)s->nb_channels);
> + av_log(ctx, AV_LOG_INFO, "Number of samples: %"PRId64"\n", nb_samples / s->nb_channels);
> + }
> }
>
> static av_cold void uninit(AVFilterContext *ctx)
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150308/cd683bd6/attachment.asc>
More information about the ffmpeg-devel
mailing list