How to Set FFmpeg sc_threshold to Zero
Setting the -sc_threshold parameter to zero in FFmpeg
disables automatic scene change detection, which is essential for
forcing consistent keyframe (I-frame) intervals during video encoding.
This article provides a direct, step-by-step guide on how to apply this
setting in your FFmpeg commands, explaining the exact syntax and the
practical scenarios where disabling scene detection is necessary, such
as for HTTP Live Streaming (HLS) and DASH packaging.
The Command Syntax
To set the scene change threshold to zero, add the
-sc_threshold 0 option to your FFmpeg command. It is
typically used in conjunction with the -g (GOP size)
parameter to ensure keyframes are placed at exact, predictable
intervals.
Here is a basic example of the command:
ffmpeg -i input.mp4 -g 60 -sc_threshold 0 output.mp4How the Parameters Work Together
-i input.mp4: Specifies the input video file.-g 60: Sets the Group of Pictures (GOP) size. In this example, it instructs FFmpeg to place a keyframe every 60 frames (which equals every 2 seconds if the video is 30 frames per second).-sc_threshold 0: Disables the scene change detection algorithm. By default, FFmpeg will insert an extra keyframe whenever it detects a major scene cut. Setting this to0prevents these extra keyframes from being created, forcing FFmpeg to stick strictly to the interval defined by-g.output.mp4: The resulting encoded output file.
Why Set sc_threshold to Zero?
In standard video encoding, letting the encoder insert keyframes at scene cuts improves visual quality and compression efficiency. However, you must disable this feature by setting the threshold to zero in the following scenarios:
- Adaptive Bitrate Streaming (HLS/DASH): Multi-bitrate streaming requires video segments to be perfectly aligned at the frame level. If one rendition inserts a keyframe at a scene cut and another does not, the segment boundaries will mismatch, causing buffering or playback errors when a user switches qualities.
- Fixed Segment Lengths: If you need to split a video into precise 2-second or 5-second segments, keyframes must occur exactly at those boundaries. Disabling scene detection guarantees this predictability.