How to Use FFmpeg sendcmd for Multiple Filter Adjustments
The sendcmd (and asendcmd for audio) filter
in FFmpeg allows you to dynamically change filter parameters at specific
timestamps during playback or rendering. This article provides a
straightforward guide on how to configure and run sendcmd
to apply multiple filter adjustments simultaneously, using both external
command files and inline commands.
Step 1: Assign Unique IDs to Your Filters
To control multiple filters at the same time, FFmpeg needs to know
exactly which filter instance you are targeting. You do this by
assigning a unique ID to each filter in your filtergraph using the
id parameter.
For example, to control both the eq
(brightness/contrast) and hue (saturation) filters, define
them like this: * eq=id=my_eq *
hue=id=my_hue
Step 2: Define the Simultaneous Commands
You can trigger multiple adjustments at the exact same timestamp. Each command must follow this syntax:
[timestamp] [target_filter] [parameter] [value];
To execute multiple adjustments simultaneously, list them sequentially using the same timestamp.
Method A: Using an External Command File (Recommended)
For complex adjustments, create a text file named
commands.txt and define your timeline:
# At 3 seconds, increase brightness and double the saturation
3.0 eq@my_eq brightness 0.3;
3.0 hue@my_hue saturation 2.0;
# At 7.5 seconds, return both parameters back to normal
7.5 eq@my_eq brightness 0.0;
7.5 hue@my_hue saturation 1.0;
Method B: Using Inline Commands
If you prefer not to use an external file, you can pass the commands
directly inside the FFmpeg command line using the c
parameter. Note that you must escape semicolons and spaces properly.
sendcmd=c='3.0 eq@my_eq brightness 0.3; 3.0 hue@my_hue saturation 2.0; 7.5 eq@my_eq brightness 0.0; 7.5 hue@my_hue saturation 1.0'
Step 3: Run the FFmpeg Command
Combine the sendcmd filter with your target filters in a
filter chain. The sendcmd filter must be placed
before the filters it is meant to control.
Example using an external file:
ffmpeg -i input.mp4 -vf "sendcmd=f=commands.txt,eq=id=my_eq,hue=id=my_hue" -c:a copy output.mp4Example using inline commands:
ffmpeg -i input.mp4 -vf "sendcmd=c='3.0 eq@my_eq brightness 0.3; 3.0 hue@my_hue saturation 2.0',eq=id=my_eq,hue=id=my_hue" -c:a copy output.mp4Key Considerations
- Filter Compatibility: Not all FFmpeg filters support runtime parameter changes. Check the FFmpeg documentation for your specific filter to ensure its options are marked as âTâ (runtime modifiable).
- Syntax Precision: Ensure every command line inside
your command file ends with a semicolon (
;). Missing semicolons will cause parser errors. - Timing: Timestamps can be written as seconds (e.g.,
3.5) or inHH:MM:SS.msecformat (e.g.,00:01:20.500).