Traffic Reducer does not use aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Xander44-4/traffic_reducer/llms.txt
Use this file to discover all available pages before exploring further.
.env file or a separate configuration layer. All runtime settings are expressed as module-level constants at the top of app.py and video_processor.py. To change a setting, edit the constant directly in the relevant source file and restart the server.
app.py constants
These constants control the sklearn prediction model, video sources, YOLO weights selection, and startup behavior.
| Constant | Default | Description |
|---|---|---|
MODEL_PATH | Hardcoded developer Windows path | Absolute path to modelo_semaforo_ia.pkl — the sklearn signal-phase model |
LOCAL_VIDEO_PATH | Computed from __file__ | os.path.join(os.path.dirname(__file__), "static", "traffic_dron_view.mp4") — path to the local fallback video |
YOUTUBE_URL | https://www.youtube.com/live/1H0iTzv2jiQ | YouTube live stream URL used in youtube mode |
PROJECT_ROOT | Computed from __file__ | Two directories above app.py; used to locate .pt weight files |
YOLO_MODEL_PATH | Auto-selected from project root | Path to the YOLOv8 .pt weights file; resolved at startup |
LOCAL_VIDEO_EXISTS | Computed at startup | True if LOCAL_VIDEO_PATH exists on disk; controls whether local mode is available |
DEFAULT_MODE | 'idle' | Startup mode: 'idle', 'youtube', or 'local' |
LOCAL_VIDEO_SPEED | 0.5 | Playback speed multiplier for local video mode |
video_processor.py constants
These constants define the output dimensions and frame rate used when decoding the YouTube live stream through FFmpeg, as well as helper values resolved once at import time.
| Constant | Value | Description |
|---|---|---|
YT_WIDTH | 854 | Output width of decoded YouTube frames (pixels) |
YT_HEIGHT | 480 | Output height of decoded YouTube frames (pixels) |
YT_TARGET_FPS | 25 | FFmpeg target frame rate for YouTube mode |
YT_FRAME_BYTES | 854 × 480 × 3 | Expected raw frame size in bytes (BGR24) |
PHASE_LABELS | {0: "NORTE", 1: "SUR", 2: "ESTE", 3: "OESTE"} | Maps integer phase IDs to direction strings |
FFMPEG_BIN | Resolved via imageio_ffmpeg | Absolute path to the FFmpeg executable bundled by imageio-ffmpeg |
NODE_PATH | Detected via shutil.which | Path to a Node.js executable if found; None otherwise |
JS_RUNTIMES | {'node': {'path': NODE_PATH}} or {} | Runtime hint dict passed to yt-dlp when Node is available |
OpenCV FFmpeg environment variables
video_processor.py sets several os.environ entries at module import time to configure OpenCV’s internal FFmpeg capture layer for low-latency, resilient live-stream ingestion:
60000 = 60 seconds). OPENCV_LOG_LEVEL = 'OFF' suppresses OpenCV’s verbose FFmpeg log output from the console.
Common configuration changes
Start in YouTube mode automatically ChangeDEFAULT_MODE in app.py so the system connects to the live stream as soon as the server starts, without requiring a manual source selection in the UI:
0.5 plays the local video at half speed to give YOLO sufficient time for inference. Increase the value to play back faster, or decrease it to slow down further: