Configure FFmpeg Color Source Resolution and Framerate
This article provides a straightforward guide on how to use the
FFmpeg color virtual input device. You will learn how to
configure essential parameters such as the color name, output
resolution, and frame rate using clear, production-ready command-line
examples.
The FFmpeg Color Source Syntax
The color source in FFmpeg is part of the
lavfi (Libavfilter) input format. It generates a solid
color video stream. To configure its properties, you pass key-value
pairs separated by colons inside the -i (input)
argument.
The basic template for the command is:
ffmpeg -f lavfi -i color=c=COLOR:s=RESOLUTION:r=FRAMERATE -t DURATION output.mp4Configuring the Parameters
You can customize the color source using either the short-form or long-form names for each parameter.
1. Color Name (c or
color)
This parameter defines the background color of the video. You can
specify it using: * Standard color names:
red, blue, green,
black, white, etc. * Hexadecimal
values: 0xRRGGBB (e.g., 0xff0000 for
red) or 0xRRGGBBAA if you want to include transparency.
2. Resolution (s or
size)
This parameter defines the width and height of the generated video
canvas. You can specify it using: * Explicit
dimensions: 1920x1080, 1280x720,
640x480 * Abbreviated sizes:
hd1080 (equivalent to 1920x1080), hd720
(equivalent to 1280x720)
3. Frame Rate (r or
rate)
This parameter sets the frames per second (FPS) of the output stream.
Common values include: * Standard integers: 24,
30, 60 * Fractional values:
29.97, 30000/1001
Practical Examples
Example 1: Standard HD Video
To generate a 5-second, 1080p blue video at 30 frames per second, use the following command:
ffmpeg -f lavfi -i color=c=blue:s=1920x1080:r=30 -t 5 output.mp4Example 2: Using Hex Colors and Custom Framerates
To generate a 10-second, 720p purple video (0x800080) at
60 frames per second:
ffmpeg -f lavfi -i color=color=0x800080:size=1280x720:rate=60 -t 10 output.mp4Note: The -t option is placed after the input to
specify the duration of the output file in seconds.