How to Use FFmpeg sendcmd to Change Filters at Runtime

This article explains how to use the FFmpeg sendcmd filter to dynamically adjust video filter parameters during runtime. You will learn the syntax of the sendcmd filter, how to format external command files with precise timestamps, and how to apply real-time changes to compatible filters—such as hue or drawtext—without needing to cut or split your video files into multiple segments.


The sendcmd filter in FFmpeg acts as a controller that dispatches commands to other filters at specific time intervals during video processing. Instead of applying a static filter effect to an entire video, you can trigger parameter changes at precise timestamps.

Step 1: Identify Filter and Command Support

Not all FFmpeg filters support runtime commands. To check if a filter supports commands, you can run ffmpeg -filters in your terminal and look for the C (Command support) flag next to the filter name.

Common filters that support commands include: * hue (for adjusting saturation, brightness, and chroma) * eq (for adjusting contrast, brightness, and saturation) * drawtext (for modifying displayed text or coordinates) * overlay (for moving overlays at specific times)

Step 2: Create a Command File

The cleanest way to use sendcmd is by writing commands in an external text file. Create a text file named commands.txt and define your timeline triggers using the following syntax:

[time] [target_filter_name_or_tag] [parameter_name] [value];

Example commands.txt

The following commands will change the video to grayscale (saturation 0) at 2 seconds, and restore normal saturation (1) at 5 seconds:

2.0 hue s 0;
5.0 hue s 1;

Step 3: Run the FFmpeg Command

To apply these changes, you must link the sendcmd filter to the target filter in your FFmpeg filtergraph. Use the following command structure:

ffmpeg -i input.mp4 -vf "sendcmd=f=commands.txt,hue=s=1" output.mp4

How it works:

  1. sendcmd=f=commands.txt reads the command schedule from your file.
  2. hue=s=1 initializes the hue filter with a default saturation of 1.
  3. As FFmpeg processes the video, sendcmd intercepts the timeline and dynamically updates the hue filter’s saturation value at 2.0 and 5.0 seconds.

Advanced: Targeting Multiple Filters

If you are using multiple instances of the same filter, you can assign unique tags to them using the @ symbol so sendcmd knows exactly which filter to target.

Example commands.txt

3.0 text1 reinit text='First Text Changed';
6.0 text2 reinit text='Second Text Changed';

FFmpeg Command

ffmpeg -i input.mp4 -vf "sendcmd=f=commands.txt,drawtext@text1=text='Original 1':x=10:y=10,drawtext@text2=text='Original 2':x=10:y=50" output.mp4

In this command, drawtext@text1 and drawtext@text2 define distinct targets, ensuring the runtime text changes are applied to the correct filters at the specified timestamps.