How to Use asendcmd Filter in FFmpeg

This guide explains how to use the asendcmd filter in FFmpeg to send commands to other audio filters at specific timestamps during processing. You will learn the basic syntax of the filter, how to format command files, and how to execute FFmpeg commands to dynamically change audio parameters like volume and panning.

Understanding asendcmd

The asendcmd (audio send command) filter allows you to pass commands to other filters in your filtergraph at precise intervals. This is highly useful for automated audio editing, such as fading volume up or down at specific times, changing panning, or adjusting equalizer settings dynamically without splitting the audio file into multiple segments.

To use asendcmd, you must: 1. Define the commands and their execution times (either in an external text file or inline). 2. Assign a unique instance name to the target filter so asendcmd knows where to send the instructions.

Command File Syntax

If you are using an external file to specify commands, the syntax for each line is:

time [enter|leave] target command arg;

Example Command File (commands.txt)

Create a text file named commands.txt with the following contents to dynamically alter volume:

2.0 volume volume 0.2;
5.0 volume volume 1.0;
8.0 volume volume 0.0;

In this example: * At 2.0 seconds, the filter named volume will reduce the gain to 0.2. * At 5.0 seconds, the volume will restore to full (1.0). * At 8.0 seconds, the volume will mute (0.0).

Running the FFmpeg Command

Once you have your command file, run FFmpeg using the asendcmd filter. You must link asendcmd to the target filter in your audio filtergraph (-af).

ffmpeg -i input.mp3 -af "asendcmd=f=commands.txt,volume@volume=1.0" output.mp3

Breakdown of the Command:

Using Inline Commands

If you only have a few simple commands, you can write them directly inside the FFmpeg command line using the c (commands) parameter instead of an external file. This avoids the need to manage extra text files.

ffmpeg -i input.mp3 -af "asendcmd=c='3.0 volume volume 0.5; 6.0 volume volume 1.0',volume@volume=1.0" output.mp3

Note: When writing inline commands, ensure you wrap the commands in single quotes to prevent your command line shell from misinterpreting the spaces and semicolons.