From cb9ff7bc861cef272397da5aaa9f3ed1fbe467f2 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Fri, 26 Sep 2025 01:33:41 +0700 Subject: [PATCH] refactor: update FFmpeg hardware acceleration to use NVDEC instead of CUVID for improved performance --- core/streaming/readers.py | 10 +++++----- core/utils/ffmpeg_detector.py | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/core/streaming/readers.py b/core/streaming/readers.py index 53c9643..32a424a 100644 --- a/core/streaming/readers.py +++ b/core/streaming/readers.py @@ -208,20 +208,20 @@ class RTSPReader: except Exception as e: logger.debug(f"Camera {self.camera_id}: FFmpeg optimal hardware acceleration not available: {e}") - # Method 3: Try FFmpeg with basic NVIDIA CUVID + # Method 3: Try FFmpeg with NVIDIA NVDEC (better for RTX 3060) if not hw_accel_success: try: import os - os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'video_codec;h264_cuvid|rtsp_transport;tcp|hwaccel;cuda|hwaccel_device;0' + os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = 'hwaccel;cuda|hwaccel_device;0|rtsp_transport;tcp' - logger.info(f"Attempting FFmpeg with basic CUVID for camera {self.camera_id}") + logger.info(f"Attempting FFmpeg with NVDEC hardware acceleration for camera {self.camera_id}") self.cap = cv2.VideoCapture(self.rtsp_url, cv2.CAP_FFMPEG) if self.cap.isOpened(): hw_accel_success = True - logger.info(f"Camera {self.camera_id}: Using FFmpeg CUVID hardware acceleration") + logger.info(f"Camera {self.camera_id}: Using FFmpeg NVDEC hardware acceleration") except Exception as e: - logger.debug(f"Camera {self.camera_id}: FFmpeg CUVID not available: {e}") + logger.debug(f"Camera {self.camera_id}: FFmpeg NVDEC not available: {e}") # Method 4: Try FFmpeg with VAAPI (Intel/AMD GPUs) if not hw_accel_success: diff --git a/core/utils/ffmpeg_detector.py b/core/utils/ffmpeg_detector.py index 92aecfc..565713c 100644 --- a/core/utils/ffmpeg_detector.py +++ b/core/utils/ffmpeg_detector.py @@ -109,11 +109,9 @@ class FFmpegCapabilities: if codec == 'h264': options.update({ 'hwaccel': 'cuda', - 'hwaccel_device': '0', - 'video_codec': 'h264_cuvid', - 'hwaccel_output_format': 'cuda' + 'hwaccel_device': '0' }) - logger.info("Using NVIDIA CUVID hardware acceleration for H.264") + logger.info("Using NVIDIA NVDEC hardware acceleration for H.264") elif codec == 'h265': options.update({ 'hwaccel': 'cuda',