Crossfade between two video clips
The `xfade` filter is a one-line dissolve between two videos. It blends the two streams for a specified duration at a specified offset, so a transition can be programmed in the filter graph without an external editor. The filter supports several transition types: fade, wipe, slide, and more.
The command
ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:v][1:v]xfade=transition=fade:duration=1:offset=10,format=yuv420p[v]" -map "[v]" -c:v libx264 -crf 20 out.mp4What it does
The filter takes the two video streams, applies the transition for `duration` seconds starting at `offset` seconds into the first stream. The default transition is a dissolve; pass `transition=wipeleft` or `transition=slidedown` for a directional effect. The output is a single video stream with the transition baked in. For a fade-in or fade-out, use the `fade` filter on a single input.
Requirements
Two video inputs of the same resolution and framerate. The filter is in libavfilter. CPU-only, single-pass. The transition is added during the encode, so the encoder spends extra bits on the blended frames — set your CRF one or two points higher than usual to keep the file size similar.
Things to avoid
- Crossfading two videos with different resolutions. The filter expects both inputs to match, so a 1080p source and a 720p source will produce a distorted output. Scale the second to match first.
- Forgetting to map the audio. The `xfade` filter operates on video; the audio is a separate stream. Add `acrossfade` to crossfade the audio at the same offset.
- Using a very long transition. A 5-second crossfade is a stylistic choice; a 30-second crossfade is a pacing problem.
- Confusing `xfade` with the `fade` filter. `fade` is for a single stream (in or out); `xfade` is for a transition between two streams.