How to Change Video Brightness Over Time with FFmpeg sendcmd
Adjusting video brightness dynamically during playback is a powerful
technique for creating transitions, correcting exposure issues, or
adding creative visual effects. This guide demonstrates how to use the
FFmpeg sendcmd filter to pass commands to the
eq (equalizer) filter, allowing you to precisely control
and alter a video’s brightness at specific timestamps.
Understanding the Components
To change brightness over time, you must chain two FFmpeg filters
together: 1. sendcmd: This filter reads
commands (either from a text file or an inline string) and dispatches
them to other filters at designated timestamps. 2.
eq: This filter adjusts video properties
like brightness, contrast, and saturation. It accepts real-time commands
to change these parameters during processing.
The brightness parameter in the eq filter accepts values
from -1.0 (completely black) to 1.0
(completely white), with 0.0 being the default utility
value.
Method 1: Using an Inline Command (For Simple Changes)
For quick adjustments, you can write the commands directly inside your terminal command.
Here is the basic syntax:
ffmpeg -i input.mp4 -vf "sendcmd=c='[time] eq brightness [value]',eq" -c:a copy output.mp4Example:
To start a video dark, increase the brightness at 2 seconds, and return it to normal at 5 seconds, use the following command:
ffmpeg -i input.mp4 -vf "sendcmd=c='0.0 eq brightness -0.5, 2.0 eq brightness 0.3, 5.0 eq brightness 0.0',eq" -c:a copy output.mp4How it works: * 0.0 eq brightness -0.5:
At 0 seconds, brightness is set to -0.5 (darker). *
2.0 eq brightness 0.3: At 2 seconds, brightness changes to
0.3 (brighter). * 5.0 eq brightness 0.0: At 5 seconds,
brightness resets to its default state. * ,eq: This
instantiates the eq filter immediately after
sendcmd so it can receive the instructions.
Method 2: Using a Command File (For Complex Timelines)
If you have many brightness changes to make, writing them inline can become messy. Instead, you can save your commands in a external text file.
Step 1: Create the command file
Create a text file named brightness_commands.txt and
define your timeline:
0.0 eq brightness -0.4;
2.5 eq brightness 0.2;
4.0 eq brightness -0.1;
6.0 eq brightness 0.0;
Note: Each command line must end with a semicolon
(;).
Step 2: Run the FFmpeg command
Point the sendcmd filter to your text file using the
f (file) parameter:
ffmpeg -i input.mp4 -vf "sendcmd=f=brightness_commands.txt,eq" -c:a copy output.mp4Key Considerations
- Abrupt Changes vs. Interpolation: The
sendcmdfilter triggers instant state changes at the exact timestamp specified. It does not automatically fade or transition smoothly between values. - Audio stream: The
-c:a copyflag is included in the examples to stream-copy the audio without re-encoding it, which saves processing time.