perf: default ffmpeg decoder thread_count to 2

libavcodec's avcodec_alloc_context3 leaves thread_count at 1, so
software 1080p H.264 decoding hits ~60ms/frame and saturates a core
per camera.  Default to 2 frame-threads, which roughly halves per-
frame decode time without oversubscribing systems with many cameras.

User can still override via thread_count in monitor Options (0 = let
ffmpeg auto-detect based on CPU count).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Isaac Connor
2026-04-15 15:58:44 -04:00
parent 5ff253b7b1
commit c2f8da3e2c

View File

@@ -422,6 +422,13 @@ int FfmpegCamera::OpenFfmpeg() {
mVideoCodecContext->framerate = mVideoStream->r_frame_rate;
mVideoCodecContext->sw_pix_fmt = chosen_codec_data->sw_pix_fmt;
// libavcodec defaults thread_count to 1, making software 1080p H.264
// decode hit ~60ms/frame and saturate a core per camera. Default to 2
// frame-threads instead. User can override (including 0 = auto) via
// thread_count in monitor Options.
mVideoCodecContext->thread_count = 2;
mVideoCodecContext->thread_type = FF_THREAD_FRAME | FF_THREAD_SLICE;
// Set default options for this codec
if (chosen_codec_data->options_defaults) {
AVDictionary *opts_defaults = nullptr;