Change FFmpeg Exposure Over Time Using Timestamps

This article explains how to dynamically adjust video exposure over time using FFmpeg’s exposure filter combined with mathematical expressions and timestamps. You will learn the syntax for creating gradual exposure transitions, triggering sudden exposure changes at specific timecodes, and how to apply these commands to your video processing workflows.

To change the exposure of a video based on a timestamp in FFmpeg, you must leverage the exposure filter’s support for evaluation expressions. Instead of passing a static number to the filter, you write a mathematical formula using the variable t (which represents the current timestamp of the frame in seconds).

The Basic Syntax

The basic syntax for the exposure filter using expressions is:

-vf "exposure=exposure='EXPRESSION'"

Within the single quotes, you can use mathematical operators, functions, and time-based variables.

Example 1: Gradual Exposure Increase (Linear Fade)

If you want the exposure to gradually increase as the video plays, you can multiply the time variable t by a scaling factor.

For example, to increase the exposure by 0.5 stops every second:

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

To prevent the exposure from increasing infinitely, use the clip function to set a minimum and maximum limit. This command caps the exposure at a maximum of 3 stops:

ffmpeg -i input.mp4 -vf "exposure=exposure='clip(t*0.5, 0, 3)'" -c:a copy output.mp4

Example 2: Sudden Exposure Change at a Specific Time

To trigger an exposure change at a specific timestamp, use the if(cond, expr1, expr2) function along with relational operators like gte (greater than or equal to).

For example, to keep the exposure at 0 for the first 5 seconds, and then instantly increase it to 1.5 stops at the 5-second mark:

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

Example 3: Creating a Fade-In and Fade-Out Effect

You can combine multiple conditions to create complex exposure transitions, such as fading the exposure up and then back down.

The following expression increases the exposure from 0 to 2 over the first 3 seconds, holds it at 2 until second 7, and then fades it back to 0 by second 10:

ffmpeg -i input.mp4 -vf "exposure=exposure='if(lt(t,3), t*(2/3), if(lt(t,7), 2, max(0, 2-(t-7)*(2/3))))'" -c:a copy output.mp4

Example 4: Oscillating Exposure (Pulse Effect)

To make the exposure pulse up and down over time, use the sine wave function sin(). The following command oscillates the exposure between -1.5 and +1.5 stops over time:

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