[Libav-user] Audio silence detector avfilter
Сергей Икол
sergbest0 at gmail.com
Mon Nov 30 12:03:41 EET 2020
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;
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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20201130/4e69499c/attachment.html>
More information about the Libav-user
mailing list