SOD Integration in LightNVR
March 16, 2025 ยท View on GitHub
This document explains how SOD (an embedded computer vision & machine learning library) is integrated into LightNVR and how to build the project with or without SOD support.
Overview
SOD is used for object detection in video streams. In previous versions of LightNVR, SOD was directly linked into the binary. Now, SOD is compiled as a standalone library that is optional and used only when available.
Building Options
Building with SOD (Default)
By default, LightNVR is built with SOD support. This means:
- SOD is compiled as a shared library (
libsod.so) - LightNVR is linked against this library
- The SOD code is directly accessible to LightNVR
To build with SOD support:
# Using the standard build script (SOD is enabled by default)
./scripts/build.sh --release
# Or explicitly enable SOD
./scripts/build.sh --release --with-sod
# Or manually
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SOD=ON ..
make -j$(nproc)
Building without SOD
You can also build LightNVR without SOD support. In this case:
- SOD is not compiled
- LightNVR is not linked against SOD
- LightNVR will attempt to dynamically load
libsod.soat runtime if it's available
To build without SOD support:
# Using the standard build script with the --without-sod option
./scripts/build.sh --release --without-sod
# Or manually
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SOD=OFF ..
make -j$(nproc)
Runtime Behavior
When Built with SOD
When LightNVR is built with SOD support:
- All SOD functionality is available
- Detection models that require SOD can be loaded and used
When Built without SOD
When LightNVR is built without SOD support:
- The system will attempt to dynamically load
libsod.soat runtime - If
libsod.sois found, SOD functionality will be available - If
libsod.sois not found, SOD functionality will be disabled, but LightNVR will still run - Detection models that require SOD will not be loadable if SOD is not available
Installation Options
Installing with SOD (Default)
By default, the installation script will install both LightNVR and the SOD library:
# Build with SOD support first
./scripts/build.sh --release
# Install with SOD support (default)
sudo ./scripts/install.sh
# Or explicitly specify SOD installation
sudo ./scripts/install.sh --with-sod
Installing without SOD
You can also install LightNVR without the SOD library:
# Build without SOD support first
./scripts/build.sh --release --without-sod
# Install without SOD
sudo ./scripts/install.sh --without-sod
Installing SOD Separately
If you build LightNVR without SOD support, you can still install SOD separately:
# Clone the repository
git clone https://github.com/yourusername/lightnvr.git
cd lightnvr
# Build just the SOD library
mkdir -p build_sod
cd build_sod
cmake ../src/sod
make -j$(nproc)
# Install the SOD library
sudo cp lib/libsod.so.1.1.9 /usr/local/lib/
sudo ln -sf /usr/local/lib/libsod.so.1.1.9 /usr/local/lib/libsod.so.1
sudo ln -sf /usr/local/lib/libsod.so.1 /usr/local/lib/libsod.so
sudo ldconfig
This will make SOD available to LightNVR at runtime, even if it was built without SOD support.
Detection Models
The following detection model types are supported:
- SOD models (
.sodextension) - SOD RealNet models (
.realnet.sodextension) - TensorFlow Lite models (
.tfliteextension)
SOD and SOD RealNet models require SOD to be available (either built-in or dynamically loaded). TensorFlow Lite models require the TensorFlow Lite library to be available.
Unified Detection Interface
LightNVR now includes a unified detection interface that supports both RealNet and CNN model architectures. This allows you to use either model type with the same API, making it easy to switch between models based on your requirements.
For more information, see SOD Unified Detection.
Test Programs
Two test programs are provided to demonstrate SOD integration:
-
test_sod_realnet- Tests SOD RealNet face detection./test_sod_realnet test.jpg face.realnet.sod output.jpg -
test_sod_unified- Tests both RealNet and CNN face detection with auto-detection of model type# For RealNet models ./test_sod_unified test.jpg face.realnet.sod output.jpg # For CNN models ./test_sod_unified test.jpg face_cnn.sod output.jpg
These test programs are built automatically when SOD support is enabled.