Change FFmpeg Audio Filters at Runtime with asendcmd

This article explains how to use the asendcmd filter in FFmpeg to dynamically modify audio filter parameters during runtime. You will learn the syntax of the command, how to target specific audio filters like volume or equalizer, and how to execute changes at precise timestamps using inline arguments or external command files.

Understanding the asendcmd Filter

The asendcmd (audio send command) filter allows you to send commands to other audio filters in the filtergraph at specified timeline intervals. For this to work, the target audio filter must support runtime changes (such as volume, pan, equalizer, or tremolo).

There are two primary ways to pass commands to asendcmd: 1. Inline commands (using the c parameter) for simple, quick adjustments. 2. External command files (using the f parameter) for complex schedules and multiple transitions.


Method 1: Using Inline Commands

Inline commands are ideal for making a single, specific change at a precise moment in your audio stream.

Syntax

asendcmd=c='[time] [target_filter_name] [parameter] [value]'

Example: Reduce Volume at 5 Seconds

To lower the volume of an audio file to 20% starting at the 5-second mark, you can chain asendcmd with the volume filter:

ffmpeg -i input.mp3 -af "asendcmd=c='5.0 volume volume 0.2',volume=1" output.mp3

Method 2: Using an External Command File

For multiple adjustments over a timeline, it is cleaner to write your commands in a text file and reference it inside the FFmpeg command.

1. Create the Command File

Create a text file named commands.txt with one command per line. Each command must end with a semicolon ;.

2.0 volume volume 0.5;
5.0 volume volume 1.5;
8.0 volume volume 0.1;

2. Run the FFmpeg Command

Use the f parameter to load your file:

ffmpeg -i input.wav -af "asendcmd=f=commands.txt,volume=1" output.wav

Target Specific Filters with Names (ID Tagging)

If you have multiple instances of the same filter in your audio chain, you must assign unique names to them using the @ symbol so asendcmd knows which one to target.

Example: Independent Volume Controls

In this example, we apply two volume filters, but we only target the second one (volume@music) at the 3-second mark.

ffmpeg -i input.wav -af "asendcmd=c='3.0 volume@music volume 0.3',volume=1,volume@music=1" output.wav

Supported Runtime Audio Filters

While many filters support runtime manipulation, the most common use cases include: