Originally published at ffmpeg-micro.com
Fading video in and out sounds like it should be simple. And it is, once you know the syntax. But FFmpeg's fade and afade filters have enough parameters that it's easy to get the timing wrong, forget the audio track entirely, or end up with a hard cut where you expected a smooth transition.
This guide covers video fades, audio fades, combining them, and how to run fade operations through an API without installing FFmpeg locally.
The quick version. To fade in the first second and fade out the last second of a 10-second video:
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1" -af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" output.mp4
Video Fade with the fade Filter
FFmpeg's fade video filter controls the visual fade. It takes three main parameters:
-
t- the type:inorout -
st- start time in seconds -
d- duration of the fade in seconds
To fade in from black over the first second:
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1" -c:a copy output.mp4
The -c:a copy flag tells FFmpeg to copy the audio stream without re-encoding. This keeps things fast when you're only changing the video.
To fade out to black over the last second of a 10-second video:
ffmpeg -i input.mp4 -vf "fade=t=out:st=9:d=1" -c:a copy output.mp4
The st=9 value means the fade starts at the 9-second mark. Since the video is 10 seconds long and the fade lasts 1 second (d=1), the math works out: 9 + 1 = 10.
You can chain both fades in a single -vf argument by separating them with a comma:
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1" -c:a copy output.mp4
Audio Fade with afade
Video fading alone leaves the audio untouched. A video that fades to black while the audio keeps playing at full volume feels jarring. The afade filter handles the audio side.
ffmpeg -i input.mp4 -af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" -c:v copy output.mp4
The afade filter uses the same t, st, and d parameters, so there's no new syntax to learn.
Combining Video and Audio Fades
Use -vf for video and -af for audio in the same command:
ffmpeg -i input.mp4 \
-vf "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1" \
-af "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1" \
output.mp4
When you're applying both video and audio filters, you can't use -c:a copy or -c:v copy because both streams need to be re-encoded.
Fade to and from Black vs White
By default, FFmpeg's fade filter fades to and from black. Change it with the color parameter:
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1:color=white" -c:a copy output.mp4
Adding Fades with the FFmpeg Micro API
If you're building a video pipeline and don't want to manage FFmpeg installations, you can run the same fade operations through the FFmpeg Micro API:
curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": [{"url": "https://example.com/input.mp4"}],
"outputFormat": "mp4",
"options": [
{"option": "-vf", "argument": "fade=t=in:st=0:d=1,fade=t=out:st=9:d=1"},
{"option": "-af", "argument": "afade=t=in:st=0:d=1,afade=t=out:st=9:d=1"}
]
}'
FAQ
How do I fade in video with FFmpeg?
Use the fade video filter: ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=1" -c:a copy output.mp4.
What is the difference between fade and afade in FFmpeg?
The fade filter applies to the video stream. The afade filter applies to the audio stream. They're independent filters that you typically use together.
How do I fade to white instead of black?
Add the color=white parameter: ffmpeg -i input.mp4 -vf "fade=t=out:st=9:d=1:color=white" -c:a copy output.mp4.
Top comments (0)