How to Set libx265 Scenecut Threshold in FFmpeg

This article explains how to configure and adjust the scene cut detection threshold in the libx265 encoder using FFmpeg. You will learn the exact commands and parameters required to control how FFmpeg detects scene changes, allowing you to optimize keyframe (I-frame) placement, improve video compression efficiency, and customize your encoding workflow.

Understanding Scene Cut Detection in x265

In H.265/HEVC video encoding, the encoder automatically inserts an I-frame (keyframe) when it detects a dramatic change in the visual content, known as a scene cut. This ensures high visual quality at the start of a new scene.

In libx265, the threshold for this detection is controlled by the scenecut parameter. * A higher value makes the encoder more sensitive to scene changes, resulting in more frequent I-frames. This can improve quality during fast transitions but increases the file size. * A lower value makes it less sensitive, resulting in fewer I-frames, which reduces file size but may cause compression artifacts during sudden scene transitions.

There are two primary ways to configure this threshold in FFmpeg.


The most direct and reliable way to pass parameters to the libx265 encoder is by using the -x265-params flag. The default scenecut threshold value in x265 is 40.

To set a custom scene cut threshold, use the following syntax:

ffmpeg -i input.mp4 -c:v libx265 -x265-params scenecut=60 output.mp4

In this example, the threshold is raised to 60, making the encoder more sensitive to scene transitions.


Method 2: Using the Native FFmpeg -sc_threshold Flag

FFmpeg has a native option called -sc_threshold. When using the libx265 encoder, FFmpeg automatically maps this flag to the x265 scenecut parameter.

To use the native FFmpeg option, run:

ffmpeg -i input.mp4 -c:v libx265 -sc_threshold 40 output.mp4

Note: While this method works, using -x265-params is generally preferred as it guarantees the parameter is passed directly to the underlying x265 library without translation errors.


How to Disable Scene Cut Detection

If you are streaming or need a strictly constant Group of Pictures (GOP) size (where keyframes occur at exact, fixed intervals), you should disable scene cut detection entirely.

To disable scene cut detection, set the value to 0:

ffmpeg -i input.mp4 -c:v libx265 -x265-params scenecut=0 output.mp4

Alternatively, you can use the no-scenecut parameter:

ffmpeg -i input.mp4 -c:v libx265 -x265-params no-scenecut=1 output.mp4

When disabled, the encoder will only insert I-frames at the exact interval defined by your -g (GOP size / keyint) parameter.