How to Dynamically Adjust Video Exposure in FFmpeg

This article explains how to use FFmpeg’s exposure filter to dynamically modify a video’s brightness over time. You will learn how to write mathematical expressions using time-based variables to create effects like gradual exposure fades, pulsing light variations, and conditional exposure corrections.

Understanding the FFmpeg Exposure Filter

The exposure filter alters the exposure of a video using logarithmic EV (Exposure Value) steps. A value of 0 leaves the video unchanged, positive values brighten the video, and negative values darken it.

To make this filter dynamic, you can leverage FFmpeg’s expression evaluation. Instead of passing a static number to the filter, you pass a mathematical formula that references time (t) or frame number (n).

The basic syntax for the filter is:

-vf "exposure=exposure='EXPRESSION'"

Practical Examples of Dynamic Exposure

1. Gradual Exposure Increase (Fade-In Effect)

To make a video start dark and gradually brighten over time, you can multiply the time variable (t) by a multiplier.

ffmpeg -i input.mp4 -vf "exposure=exposure='t*0.5'" -c:a copy output.mp4

2. Pulsing or Oscillating Exposure

You can create a pulsing light effect by using trigonometric functions like sine (sin).

ffmpeg -i input.mp4 -vf "exposure=exposure='sin(t)*1.5'" -c:a copy output.mp4

3. Triggering Exposure Changes at Specific Times

If you want to adjust the exposure only after a certain timestamp, you can use the if() evaluation function.

ffmpeg -i input.mp4 -vf "exposure=exposure='if(gt(t,3), -1.5, 0)'" -c:a copy output.mp4

4. Smooth Exposure Transition Between Specific Timestamps

To smoothly transition exposure from one value to another between two specific time frames, use a combination of clip and linear interpolation formulas.

ffmpeg -i input.mp4 -vf "exposure=exposure='clip(-2 + (t-2)*1, -2, 1)'" -c:a copy output.mp4