Skip to content

How to Use FFmpeg Filter Complex

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Use FFmpeg Filter Complex. We cover key concepts, practical examples, and best practices.

The Problem

Your FFmpeg filter_complex command fails with Invalid filtergraph, Filter 'overlay' has an unconnected output, or Error initializing complex filters. Filter complex chains for multi-stream operations require precise syntax and connection labels.

Quick Fix

Fix 1: Basic Filter Complex Syntax

WRONG — using the wrong label syntax:

ffmpeg -i input.mp4 -filter_complex "scale=1280:720" output.mp4
# (this works without filter_complex — use -vf instead)

RIGHT — use filter_complex for multi-input/multi-output scenarios:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
    "[0:v]scale=1280:720[v0]; [1:v]scale=1280:720[v1]; [v0][v1]hstack[out]" \
    -map "[out]" output.mp4

Fix 2: Unlabeled Connections

ffmpeg -i bg.mp4 -i overlay.png -filter_complex "overlay=10:10" output.mp4
# (overlay expects two inputs, but filter_complex does not connect them)

RIGHT — explicitly label streams:

ffmpeg -i bg.mp4 -i overlay.png -filter_complex \
    "[0:v][1:v]overlay=10:10[out]" -map "[out]" output.mp4

Fix 3: Overlay Position

ffmpeg -i bg.mp4 -i overlay.png -filter_complex \
    "[0:v][1:v]overlay=(W-w)/2:(H-h)/2[out]" -map "[out]" output.mp4
# (centers the overlay on the background)

Fix 4: Split Stream into Multiple Outputs

ffmpeg -i input.mp4 -filter_complex "[0:v]split[1][2]" \
    -map "[1]" left.mp4 -map "[2]" right.mp4

Fix 5: Concatenate Videos

WRONG — using concat without proper stream mapping:

ffmpeg -i part1.mp4 -i part2.mp4 -filter_complex "concat=n=2" output.mp4
# Filter 'concat' has an unconnected output

RIGHT — concat requires both video and audio streams:

ffmpeg -i part1.mp4 -i part2.mp4 -filter_complex \
    "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]" \
    -map "[outv]" -map "[outa]" output.mp4

Fix 6: Debug Filter Graph

ffmpeg -i input.mp4 -filter_complex "[0:v]scale=1280:720" -t 10 -f null -
# (preview without writing output)

Use -v debug to see the filter graph dump:

ffmpeg -v debug -i input.mp4 -filter_complex "[0:v]scale=1280:720[out]" -map "[out]" -f null -
# Output includes:
# [Parsed_scale_0 @ 0x...] Setting 'w' to value '1280'
# [graph_0_in_0_0 @ 0x...] Setting 'video_size' to value '1920x1080'

Use DodaTech's Filter Graph Visualizer to design complex filter chains interactively and generate FFmpeg commands.

Prevention

  • Always label filter inputs and outputs with [labels].
  • Use -vf for single-input filters, -filter_complex for multi-input.
  • Test the filter graph with -t 10 on a short segment.
  • Use -v debug to see parsed filter settings.
  • Escape special characters in Windows batch files with ^ (caret).

Common Mistakes with filter complex

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world FFMPEG code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between -vf and -filter_complex?

-vf (video filter) applies to a single video stream. -filter_complex handles multiple inputs, multiple outputs, or filters that need streams from different sources. Use -filter_complex for overlays, concat, or split operations.

How do I chain multiple filters?

Separate filters with commas: [0:v]scale=1280:720,format=yuv420p[out]. The output of scale feeds into format. Use semicolons to separate filter chains: [0:v]scale=...; [1:v]scale=....

Why does my filter work with -vf but not with -filter_complex?

With -vf, the filter chain is automatically connected to the input and output. With -filter_complex, you must explicitly label and map everything: [0:v]filter[out]; [out]...; ... -map "[out]".

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro