Configure libx265 Profile Parameter in FFmpeg
This article provides a straightforward guide on how to configure the
profile parameter for the libx265 (HEVC) encoder in FFmpeg.
You will learn the correct command-line syntax, the available profile
options—such as main, main10, and mainstillpicture—and how to apply them
to optimize your video encoding workflow for compatibility and color
depth.
To configure the profile in FFmpeg using the libx265
encoder, you use the -profile:v flag. This parameter tells
the encoder which HEVC profile standard to target, ensuring the output
video is compatible with specific playback devices.
Basic Syntax
The standard syntax for setting the profile is:
ffmpeg -i input.mp4 -c:v libx265 -profile:v <profile_name> output.mp4Replace <profile_name> with one of the supported
HEVC profiles.
Supported libx265 Profiles
The three most common profiles used with libx265
are:
main: Standard 8-bit 4:2:0 video. This profile offers the widest compatibility with older hardware decoders, streaming devices, and smart TVs.main10: 10-bit 4:2:0 video. This is ideal for HDR (High Dynamic Range) content and significantly reduces color banding in gradients.mainstillpicture: Optimized for encoding a single still image with high compression.
The Relationship Between Profile and Pixel Format
When setting a profile, you must ensure your pixel format
(-pix_fmt) matches the color depth of that profile. If
there is a mismatch, FFmpeg may output an error or override your
settings.
Example 1: Force Main (8-bit) Profile
To encode a highly compatible 8-bit HEVC video, pair the
main profile with the yuv420p pixel
format:
ffmpeg -i input.mp4 -c:v libx265 -profile:v main -pix_fmt yuv420p output.mp4Example 2: Force Main 10 (10-bit) Profile
For high-quality 10-bit encodes, pair the main10 profile
with the yuv420p10le pixel format:
ffmpeg -i input.mp4 -c:v libx265 -profile:v main10 -pix_fmt yuv420p10le output.mp4Passing Parameters Directly to x265
Alternatively, you can configure the profile directly inside the
-x265-params option. This is useful if you are passing
multiple x265-specific variables at once:
ffmpeg -i input.mp4 -c:v libx265 -x265-params profile=main10 -pix_fmt yuv420p10le output.mp4Using either -profile:v or the -x265-params
method will successfully limit the HEVC stream to your specified profile
constraint.