How to Use FFmpeg Filter Complex
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
-vffor single-input filters,-filter_complexfor multi-input. - Test the filter graph with
-t 10on a short segment. - Use
-v debugto see parsed filter settings. - Escape special characters in Windows batch files with
^(caret).
Common Mistakes with filter complex
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro