<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 30, 2020 at 11:04 AM Сергей Икол <<a href="mailto:sergbest0@gmail.com">sergbest0@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello everybody!<br>I need help solving my problem.<br><br>I wanted to make a C++ implementation of the Audio silence detector. I used the example from github (<a href="https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/af_silencedetect.c" target="_blank">https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/af_silencedetect.c</a>). I have also simplified this example to the following form.<div><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">nb_samples</span> = <span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">frame</span>-><span style="color:rgb(156,220,254)">nb_samples</span> * <span style="color:rgb(156,220,254)">nb_channels</span>;</div></div></div></blockquote><div><br></div><div>This code reads out of bounds, because nb_samples for planar sample format you use below is wrongly calculated.</div><div><br></div><div>Note difference between planar and packed sample formats.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div> <span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(78,201,176)">int64_t</span> <span style="color:rgb(156,220,254)">nb_samples_notify</span> = <span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">srate</span> * <span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">duration</span> * <span style="color:rgb(106,153,85)">this->nb_channels:</span></div></div><div><span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">frame</span>-><span style="color:rgb(156,220,254)">format</span> == <span style="color:rgb(79,193,255)">AV_SAMPLE_FMT_S16P</span>) {</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(78,201,176)">int16_t</span> *<span style="color:rgb(156,220,254)">p</span> = (<span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(78,201,176)">int16_t</span> *)<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">frame</span>-><span style="color:rgb(156,220,254)">data</span>[<span style="color:rgb(181,206,168)">0</span>];</div></blockquote><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(156,220,254)">i</span> = <span style="color:rgb(181,206,168)">0</span>; <span style="color:rgb(156,220,254)">i</span> < <span style="color:rgb(156,220,254)">nb_samples</span>; <span style="color:rgb(156,220,254)">i</span>++, <span style="color:rgb(156,220,254)">p</span>++) {</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(197,134,192)">if</span> (*<span style="color:rgb(156,220,254)">p</span> < <span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">noise</span> && *<span style="color:rgb(156,220,254)">p</span> > -<span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">noise</span>) {</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(197,134,192)">if</span> (!<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">start</span>) {</div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">nb_null_samples</span>++;</div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">nb_null_samples</span> >= <span style="color:rgb(156,220,254)">nb_samples_notify</span>) {<span style="color:rgb(106,153,85)"> //nb_samples_notify</span></div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">start</span> = <span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">frame</span>-><span style="color:rgb(156,220,254)">pts</span> - (<span style="color:rgb(78,201,176)">int64_t</span>)(<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">duration</span> / <span style="color:rgb(220,220,170)">av_q2d</span>(<span style="color:rgb(156,220,254)">time_base</span>) + <span style="color:rgb(181,206,168)">.5</span>);</div></blockquote></blockquote></blockquote></blockquote><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(78,201,176)">Log</span>::<span style="color:rgb(220,220,170)">write</span>(<span style="color:rgb(206,145,120)">"silence detected start = "</span> <span style="color:rgb(220,220,170)">+</span> <span style="color:rgb(78,201,176)">std</span>::<span style="color:rgb(220,220,170)">to_string</span>(<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(220,220,170)">getCurrentSec</span>()));</div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> }</div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> }</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> } <span style="color:rgb(197,134,192)">else</span> {</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(197,134,192)">if</span> (<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">start</span>) {</div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silent</span> = <span style="color:rgb(86,156,214)">false</span>;</div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(78,201,176)">Log</span>::<span style="color:rgb(220,220,170)">write</span>(<span style="color:rgb(206,145,120)">"silence detected end = "</span> <span style="color:rgb(220,220,170)">+</span> <span style="color:rgb(78,201,176)">std</span>::<span style="color:rgb(220,220,170)">to_string</span>(<span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(220,220,170)">getCurrentSec</span>()));</div></blockquote></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> }</div></blockquote></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">nb_null_samples</span> = <span style="color:rgb(86,156,214)">this</span>-><span style="color:rgb(156,220,254)">silence</span>-><span style="color:rgb(156,220,254)">start</span> = <span style="color:rgb(181,206,168)">0</span>;</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> }</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> }</div></blockquote><div> }</div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"></div><div><br></div><div>nb_samples = 2304</div><div>srate = 48000</div><div>nb_chaneks = 2</div><div>noise = 0.001</div><div>duratiion = 0.7</div><div>//</div><div>input video file format - * .ts<br>audio codec - mp2<br></div><div><br>In "*p" I get very strange data (for example -22634) and as a result, silence was not detected.<br><br>Please tell me what I'm doing wrong? (because ffmpeg can find silence in this file)<br></div><div><br></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div></div>