[Libav-user] Audio silence detector avfilter
Paul B Mahol
onemda at gmail.com
Mon Nov 30 12:07:52 EET 2020
On Mon, Nov 30, 2020 at 11:04 AM Сергей Икол <sergbest0 at gmail.com> wrote:
> Hello everybody!
> I need help solving my problem.
>
> I wanted to make a C++ implementation of the Audio silence detector. I
> used the example from github (
> https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/af_silencedetect.c).
> I have also simplified this example to the following form.
> const int nb_samples = this->frame->nb_samples * nb_channels;
>
This code reads out of bounds, because nb_samples for planar sample format
you use below is wrongly calculated.
Note difference between planar and packed sample formats.
> const int64_t nb_samples_notify = this->srate * silence->duration *
> this->nb_channels:
> if (this->frame->format == AV_SAMPLE_FMT_S16P) {
>
> const int16_t *p = (const int16_t *)this->frame->data[0];
>
>
> for (int i = 0; i < nb_samples; i++, p++) {
>
> if (*p < this->silence->noise && *p > -silence->noise) {
>
> if (!this->silence->start) {
>
> this->silence->nb_null_samples++;
>
> if (this->silence->nb_null_samples >= nb_samples_notify) {
> //nb_samples_notify
>
> this->silence->start = this->frame->pts - (int64_t)(this->silence->
> duration / av_q2d(time_base) + .5);
>
>
> Log::write("silence detected start = " + std::to_string(this->
> getCurrentSec()));
>
> }
>
> }
>
> } else {
>
> if (this->silence->start) {
>
> this->silent = false;
>
> Log::write("silence detected end = " + std::to_string(this->getCurrentSec
> ()));
>
> }
>
> this->silence->nb_null_samples = this->silence->start = 0;
>
> }
>
> }
>
> }
>
> nb_samples = 2304
> srate = 48000
> nb_chaneks = 2
> noise = 0.001
> duratiion = 0.7
> //
> input video file format - * .ts
> audio codec - mp2
>
> In "*p" I get very strange data (for example -22634) and as a result,
> silence was not detected.
>
> Please tell me what I'm doing wrong? (because ffmpeg can find silence in
> this file)
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20201130/89d3ca31/attachment.html>
More information about the Libav-user
mailing list