Thank you so much. Yes it solved my problem пн, 30 лист. 2020 о 12:38 Paul B Mahol <[email protected]> пише:
> > > On Mon, Nov 30, 2020 at 11:04 AM Сергей Икол <[email protected]> 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 >> [email protected] >> https://ffmpeg.org/mailman/listinfo/libav-user >> >> To unsubscribe, visit link above, or email >> [email protected] with subject "unsubscribe". > > _______________________________________________ > Libav-user mailing list > [email protected] > https://ffmpeg.org/mailman/listinfo/libav-user > > To unsubscribe, visit link above, or email > [email protected] with subject "unsubscribe".
_______________________________________________ Libav-user mailing list [email protected] https://ffmpeg.org/mailman/listinfo/libav-user To unsubscribe, visit link above, or email [email protected] with subject "unsubscribe".
