Complex audio volume changes with ffmpeg
<p>Using <code>ffmpeg</code>, how much control can we have over the audio levels? For example, I would like to map an "M" shape over the program's timeline:</p>

<pre><code>t0 - t1 : fade in from 0 to 1
t1 - t2 : play at full volume
t2 - t3 : fade out to 25%
t3 - t4 : play at 25% volume
t4 - t5 : fade in (from 25%) to full volume
t5 - t6 : play at full volume
t6 - t7 : fade out from 1 to 0
</code></pre>

<p>Can this be done? The combinations I've tried (of afade and volume, and using timeline editing) have not been successful so far.</p>

<p>Here is something that is close:</p>

<pre><code>ina="infile.caf"
out="outfile.mp3"

time ffmpeg -i $ina -af \
"afade=enable='between(t,0,3)':t=in:ss=0:d=3, \
afade=enable='between(t,7,8)':t=out:st=7:d=1, \
volume=enable='between(t,8,12)':volume=.25:eval=frame, \
afade=enable='between(t,12,13)':t=in:st=12:d=1, \
afade=enable='between(t,15,18)':t=out:st=15:d=3" \
$out
</code></pre>

<p>.. but at the two middle points (the point where it fades out to 25%, and the point where it fades back in to full volume) there are glitches - audible sound clicks.</p>