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;

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.mp3

Key Elements of the Command: