How to Use the FFmpeg Color Filter
The FFmpeg color filter is a virtual input source that
allows you to generate a video stream consisting of a single, solid
color. This article provides a quick guide on how to use this filter to
create solid color backgrounds, define custom resolutions, set specific
frame rates, and control duration for your video processing
projects.
Basic Syntax of the Color Filter
The color filter is part of the lavfi
(Libavfilter virtual input) format. The basic structure of the command
requires you to specify the input format as lavfi and call
the color filter with your desired parameters:
ffmpeg -f lavfi -i color=c=blue -t 5 output.mp4In this basic example, FFmpeg generates a blue video with a default
resolution (320x240) and frame rate (25 fps), and the -t 5
flag limits the output duration to 5 seconds.
Key Parameters for the Color Filter
To customize the generated video, you can pass several parameters
inside the color filter, separated by colons
(:):
color(orc): Specifies the color of the video. You can use standard color names (e.g.,black,red,white,aquamarine) or hex values (e.g.,#FF5733or0x123456).size(ors): Defines the resolution of the output video. You can use standard abbreviations likehd1080or write the dimensions explicitly (e.g.,1920x1080).rate(orr): Sets the frame rate (e.g.,30or60).duration(ord): Specifies how long the video should play (in seconds).
Practical Examples
1. Create a Full HD Black Video
To create a standard 10-second black video in 1080p at 30 frames per second:
ffmpeg -f lavfi -i color=c=black:s=1920x1080:r=30:d=10 output.mp42. Use Hex Color Codes
If you need a specific brand color, you can use a hex code. Note that
you must escape the # symbol or wrap the filter chain in
quotes:
ffmpeg -f lavfi -i color=c='#FF5733':s=1280x720:d=5 output.mp43. Create a Transparent Video Background
If you want to generate a transparent background (useful for overlays
and complex compositing), you can use the color name
transparent or set the color to none, which
creates a channel with zero alpha value:
ffmpeg -f lavfi -i color=c=transparent:s=1920x1080:d=5 -c:v png output.mov(Note: To retain transparency, you must export to a codec that supports alpha channels, such as ProRes or PNG).
Using the Color Filter in Complex Filtergraphs
You can also use the color filter inside a
filter_complex graph as a background canvas for other
assets, such as overlaying an image or a text watermark:
ffmpeg -f lavfi -i color=c=darkblue:s=1920x1080:d=5 -i logo.png -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-10:main_h-overlay_h-10" output.mp4This command generates a dark blue 1080p background and overlays
logo.png in the bottom-right corner.