<p>Commands are instructions sent from an interface external to the filter, usually an external program using a ZMQ protocol. There is a filter that can execute commands which is what I'll use here. </p>

<p>Base syntax is</p>

<pre><code>ffmpeg -i in -af "asendcmd=c='0.0 afftdn@n sn start; 1.0 afftdn@n sn stop',afftdn@n" noiseout.wav
</code></pre>

<p>To use another source for noise profile, you'll have to append it, measure noise, and then remove it.</p>

<pre><code>ffmpeg -i in -i profile -filter_complex "[1][0]concat=n=2:v=0:a=1,asendcmd=c='0.0 afftdn@n sn start; 1.0 afftdn@n sn stop',afftdn@n,atrim=1,asetpts=PTS-STARTPTS" noiseout.wav
</code></pre>

<p>Above, I assume the profile is 1 second long, which is removed with atrim after denoising.</p>

CC BY-SA 4.0
2020-01-13T06:52:01.827Z
2020-01-13T06:52:01.827Z
Gyan
<p>This worked beautifully, many thanks to @Gyan.</p>
<p>Just to add to the accepted answer, as I needed to do this for a large number of mp3 audio files with similar noise profiles and with a naming scheme of 001_somefile.mp3. I wrote myself a batch script to do so. The <code>-y</code> confirms overwrite and the <code>|| pause</code> causes the script to halt if the command was bad. I don't know if there's any available constants to automagically obtain the length of the <code>noise_profile.mp3</code> input, so I hard-coded the 0.89 seconds length:</p>
<pre><code>@echo off

for /F &quot;usebackq delims=&quot; %%f in (`dir /B ???_*.mp3`) do (
   ffmpeg -y -i &quot;%%f&quot; -i noise_sample.mp3 -filter_complex &quot;[1][0]concat=n=2:v=0:a=1,asendcmd=c='0.0 afftdn@n sn start; 0.89 afftdn@n sn stop',afftdn@n,atrim=0.89,asetpts=PTS-STARTPTS&quot; &quot;0%%f&quot; || pause
)
</code></pre>

CC BY-SA 4.0
2023-01-28T19:25:59.287Z
2023-01-28T19:25:59.287Z
Musical BenjiMan
<p>The FFmpeg documentation for the afftdn audio filter says for the <code>-sn</code> flag:</p>

<blockquote>
  <p><strong>sample_noise, sn</strong><br>
  Start or stop measuring noise profile. Syntax for the command is : "start" or "stop" string. After measuring noise profile is stopped it will be automatically applied in filtering.</p>
</blockquote>

<p>It's a little unclear as to the basic implementation of the start/stop values in the sample_noise -sn flag. I tried:</p>

<pre><code>ffmpeg -i inputfile.wav -af afftdn=nt=c:bn=sn=start=0=stop=1 noiseout.wav
</code></pre>

<p>as an attempt to sample the first second of sound as a noise profile, which errors with</p>

<blockquote>
<pre><code>[afftdn @ 0x7fefbb800000] Custom band noise must be integer.
</code></pre>
</blockquote>

<p>So the questions are:</p>

<ol>
<li><p>What's the correct input format for sample_noise?</p></li>
<li><p>Is there a way to sample the noise from a noise reference <code>.wav</code> file that I have, e.g. <code>noiseprofile.wav</code>?</p></li>
</ol>

<ffmpeg><audio><audio-quality><noise-reduction><noise>
How can you use ffmpeg's afftdn -sn flag to sample noise from a reference noise file?
BreadEagles
# How can you use ffmpeg's afftdn -sn flag to sample noise from a reference noise file?

(Asked by: username_0 on 2020-01-13)

The FFmpeg documentation for the afftdn audio filter says for the -sn flag:

sample_noise, sn
  Start or stop measuring noise profile. Syntax for the command is : "start" or "stop" string. After measuring noise profile is stopped it will be automatically applied in filtering.

It's a little unclear as to the basic implementation of the start/stop values in the sample_noise -sn flag. I tried:
ffmpeg -i inputfile.wav -af afftdn=nt=c:bn=sn=start=0=stop=1 noiseout.wav

as an attempt to sample the first second of sound as a noise profile, which errors with

[afftdn @ 0x7fefbb800000] Custom band noise must be integer.


So the questions are:

What's the correct input format for sample_noise?
Is there a way to sample the noise from a noise reference .wav file that I have, e.g. noiseprofile.wav?

**Tags:** ffmpeg, audio, audio-quality, noise-reduction, noise


---

## 2 answers

### Answer by username_1 on 2020-01-13. Score: 2 | Accepted answer

Commands are instructions sent from an interface external to the filter, usually an external program using a ZMQ protocol. There is a filter that can execute commands which is what I'll use here. 
Base syntax is
ffmpeg -i in -af "asendcmd=c='0.0 afftdn@n sn start; 1.0 afftdn@n sn stop',afftdn@n" noiseout.wav

To use another source for noise profile, you'll have to append it, measure noise, and then remove it.
ffmpeg -i in -i profile -filter_complex "[1][0]concat=n=2:v=0:a=1,asendcmd=c='0.0 afftdn@n sn start; 1.0 afftdn@n sn stop',afftdn@n,atrim=1,asetpts=PTS-STARTPTS" noiseout.wav

Above, I assume the profile is 1 second long, which is removed with atrim after denoising.


---

### Answer by username_2 on 2023-01-28. Score: 1

This worked beautifully, many thanks to @username_1.
Just to add to the accepted answer, as I needed to do this for a large number of mp3 audio files with similar noise profiles and with a naming scheme of 001_somefile.mp3. I wrote myself a batch script to do so. The -y confirms overwrite and the || pause causes the script to halt if the command was bad. I don't know if there's any available constants to automagically obtain the length of the noise_profile.mp3 input, so I hard-coded the 0.89 seconds length:
@echo off

for /F "usebackq delims=" %%f in (`dir /B ???_*.mp3`) do (
   ffmpeg -y -i "%%f" -i noise_sample.mp3 -filter_complex "[1][0]concat=n=2:v=0:a=1,asendcmd=c='0.0 afftdn@n sn start; 0.89 afftdn@n sn stop',afftdn@n,atrim=0.89,asetpts=PTS-STARTPTS" "0%%f" || pause
)


---

