How to Write FFmpeg asendcmd Command Files
This article explains how to write and format a command file for the
FFmpeg asendcmd (audio send command) filter. You will learn
the exact syntax required to trigger parameter changes in other audio
filters at specific timestamps, enabling dynamic audio processing and
automation throughout your media timeline.
Understanding the asendcmd Syntax
The asendcmd filter reads a text file containing
commands and passes them to other filters in your FFmpeg filtergraph at
designated times.
Each line in your command file must follow this specific syntax structure:
time [target] command arguments;
- time: The precise time when the command should be
triggered. You can write this as a decimal number of seconds (e.g.,
2.5) or in thehh:mm:ss.msecformat (e.g.,00:00:02.500). - target: The identifier of the filter you want to target. This is defined by assigning a name to the filter in your filtergraph.
- command: The specific command supported by the target filter.
- arguments: The new parameters or values you want to apply.
- Semicolon (;): Each command line must end with a semicolon.
You can also include comments in your command file by starting a line
with the # character.
Step-by-Step Command File Example
To change audio parameters dynamically, you must first create a text
file. In this example, we will create a file named
commands.txt to dynamically adjust the volume of an audio
stream.
# Reduce volume to 20% at 2.5 seconds
2.5 [my_volume] volume 0.2;
# Restore volume to 100% at 7.0 seconds
7.0 [my_volume] volume 1.0;
In this file: * [my_volume] is the target label we will
assign to our volume filter. * volume is the command that
the volume filter accepts to change its gain. * 0.2 and
1.0 are the arguments representing the scale of the
volume.
Running the FFmpeg Command
To apply this command file, use the asendcmd filter in
your FFmpeg filtergraph. You must load the command file using the
f (filename) parameter and link the target label to the
filter you wish to manipulate.
Run the following command in your terminal:
ffmpeg -i input.mp3 -filter_complex "asendcmd=f=commands.txt,volume=@my_volume:eval=frame" output.mp3Key Elements of the Command:
asendcmd=f=commands.txt: Tells FFmpeg to load your text file.volume=@my_volume: Applies the labelmy_volumeto the volume filter, matching the target identifier used inside your command file.eval=frame: Instructs the volume filter to evaluate expressions on a per-frame basis, which is required for real-time dynamic changes to take effect.