Skip to main content

Overview

Video mode records an MP4 video clip for the entire duration a person is present in the camera frame. Recording starts when a person enters and stops when they exit, capturing the complete event timeline.

How It Works

When running in video mode (--save video):
  1. Detection: The system analyzes every Nth frame for person presence
  2. Entry Detection: When a person enters the frame, recording begins immediately
  3. Continuous Recording: Every frame is written to the MP4 file while at least one person is detected
  4. Exit Detection: After 3 consecutive detection cycles with no person, recording stops and the file is saved
  5. Waiting State: The system continues monitoring for the next entry event
Video mode captures full presence duration, not just a snapshot. This is ideal for reviewing behavior, incidents, or complete interactions.

Basic Usage

Output:

Output Files

File Naming Convention

Single Stream:
Example: person_clip_1_20260309_143022_1741528222.mp4 Multiple Streams:
Example: output/stream_1/person_clip_1_20260309_143022_1741528222.mp4

File Structure

Clip duration varies based on how long the person remains in frame. Short clips (< 5 seconds) may indicate a person walking through quickly.

Video Codec and Settings

Default Settings

The system automatically configures video encoding:
  • Codec: MP4V (MPEG-4 Part 2)
  • FPS: Matches source stream (auto-detected, defaults to 25 fps if unknown)
  • Resolution: Original stream resolution (no resizing)
  • Format: .mp4 container

FPS Detection

From stream_processor.py:79-81:
The system reads the stream’s FPS metadata. If invalid (≤0 or >120), it defaults to 25 fps.

Video Writer Initialization

From stream_processor.py:153-156:
All recorded clips preserve the original stream’s frame rate and resolution. No transcoding or resizing is performed during recording.

Use Cases

1

Incident Review

Record complete events for later review:
Each clip contains the full event timeline from entry to exit.
2

Behavior Analysis

Capture interactions and movement patterns:
Review customer behavior, dwell times, and traffic patterns.
3

Multi-Camera Recording

Monitor multiple locations simultaneously:
Each camera records independently when motion is detected.
4

Long-Term Surveillance

Optimize storage by recording only when people are present:
Saves disk space compared to 24/7 recording.

Exit Detection Behavior

Three-Strike Rule

The system uses a conservative exit detection to prevent premature clip termination: From stream_processor.py:77:
A person must be absent for 3 consecutive detection cycles before the clip stops recording. Example with frame-skip 15:
  1. Frame 15: Person detected → recording
  2. Frame 30: Person detected → still recording
  3. Frame 45: No person (1/3) → continue recording
  4. Frame 60: No person (2/3) → continue recording
  5. Frame 75: No person (3/3) → stop recording
This prevents clips from stopping when detection temporarily fails (person turns away, occlusion, etc.). You’ll capture a few extra frames after exit, which is usually preferable to cutting off early.

Storage Considerations

Estimating Disk Usage

Approximate file sizes for MP4V codec: Multi-stream example:
  • 4 cameras at 1280×720, 30 fps
  • Average 20 person entries per camera per day
  • Average 15 seconds per clip
  • Daily storage: 4 × 20 × 7.5 MB = 600 MB/day

Managing Storage

Advanced Configuration

Adjusting Exit Sensitivity

The exit threshold is hardcoded in stream_processor.py:77. To customize, modify the source:

Custom Output Directory

Edit config.cfg:

Frame Skip Optimization

Balance detection speed vs. CPU usage:
frame-skip only affects detection frequency. All frames are recorded to the video file, regardless of the skip value.

Monitoring Live Recording

Console Output

The console shows real-time recording status:

Live Display

Enable grid display for multiple streams:
Press ‘q’ in the window to stop all streams.

Troubleshooting

The person may be temporarily undetected. Try:
  • Lower --confidence threshold
  • Reduce --frame-skip for more frequent detection
  • Increase NO_PERSON_EXIT_THRESHOLD in source code
Recording continues until 3 consecutive non-detections. This is intentional to prevent premature cutoff. If you need shorter clips, modify NO_PERSON_EXIT_THRESHOLD in stream_processor.py:77.
If the program crashes during recording, the clip may be corrupted. The system releases the video writer in a finally block, but sudden termination (kill -9, power loss) can corrupt the file.Prevention:
  • Use proper shutdown (Ctrl+C)
  • Run in a container with restart policies
  • Implement external monitoring
Video mode uses significantly more storage than image mode. Solutions:
  • Increase --frame-skip to detect less frequently
  • Increase --area-threshold to ignore distant persons
  • Implement automatic cleanup scripts
  • Use external archival storage
Check:
  • Detection thresholds (try lowering --confidence)
  • Stream resolution and quality
  • Use --test-image to verify detection works

Image Mode

Capture snapshots on person entry

Test Image

Test detection with a local image file