How to Generate Solid Color Video with FFmpeg
This article provides a quick and practical guide on how to use the
FFmpeg color source filter to generate a solid color video
stream. You will learn the basic command syntax, how to specify custom
colors using names or hex codes, and how to configure essential video
properties such as resolution, frame rate, and duration.
The Basic Command
To generate a solid color video, you need to use FFmpeg’s virtual
input device lavfi (Libavfilter) and invoke the
color source filter.
Here is the simplest command to generate a 5-second black video:
ffmpeg -f lavfi -i color -t 5 output.mp4-f lavfi: Forces the input format to be the Libavfilter virtual input.-i color: Invokes the default color filter (which outputs a black screen at 320x240 resolution and 25 fps).-t 5: Limits the duration of the output video to 5 seconds.
Customizing Color, Resolution, and Frame Rate
You can customize the video stream by passing specific parameters to
the color filter. The basic syntax for passing parameters
is color=parameter1=value1:parameter2=value2.
The primary parameters are: * color (or
c): Specifies the color. You can use standard
color names (e.g., red, blue,
white) or hex triplets (e.g., 0xff0000 or
#123456). * size (or
s): Sets the resolution (width x height). The
default is 320x240. * rate (or
r): Sets the frame rate. The default is
25. * duration (or
d): Sets the duration of the video. You can set
this within the filter instead of using the global -t
flag.
Examples
1. Generate a 1080p Blue Video at 30 fps for 10 Seconds
To create a standard Full HD blue video, use the following command:
ffmpeg -f lavfi -i color=c=blue:s=1920x1080:r=30 -t 10 output.mp42. Generate a Green Video Using Hex Codes and Internal Duration
If you want to use a specific hex color code (e.g., pure green
#00FF00) and define the duration inside the filter itself,
run:
ffmpeg -f lavfi -i color=c=0x00FF00:s=1288x720:d=7 output.mp4Note: When using hex codes, prefix the color value with
0x instead of # to prevent command-line
parsing errors.
Common Use Cases
Generating a solid color video stream is highly useful for: * Creating a blank video background for overlays. * Adding intro or outro black screens to an existing video. * Testing video pipelines, streaming bandwidth, and encoder performance with a consistent, low-complexity source.