From c2f8da3e2c85f343e9b402174cdc464ba920446f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 15 Apr 2026 15:58:44 -0400 Subject: [PATCH] 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) --- src/zm_ffmpeg_camera.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 193b4ae77..b0e2f2319 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -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;