Skip to main content

Documentation 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.

Traffic Reducer does not use a .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.
ConstantDefaultDescription
MODEL_PATHHardcoded developer Windows pathAbsolute path to modelo_semaforo_ia.pkl — the sklearn signal-phase model
LOCAL_VIDEO_PATHComputed from __file__os.path.join(os.path.dirname(__file__), "static", "traffic_dron_view.mp4") — path to the local fallback video
YOUTUBE_URLhttps://www.youtube.com/live/1H0iTzv2jiQYouTube live stream URL used in youtube mode
PROJECT_ROOTComputed from __file__Two directories above app.py; used to locate .pt weight files
YOLO_MODEL_PATHAuto-selected from project rootPath to the YOLOv8 .pt weights file; resolved at startup
LOCAL_VIDEO_EXISTSComputed at startupTrue if LOCAL_VIDEO_PATH exists on disk; controls whether local mode is available
DEFAULT_MODE'idle'Startup mode: 'idle', 'youtube', or 'local'
LOCAL_VIDEO_SPEED0.5Playback 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.
ConstantValueDescription
YT_WIDTH854Output width of decoded YouTube frames (pixels)
YT_HEIGHT480Output height of decoded YouTube frames (pixels)
YT_TARGET_FPS25FFmpeg target frame rate for YouTube mode
YT_FRAME_BYTES854 × 480 × 3Expected raw frame size in bytes (BGR24)
PHASE_LABELS{0: "NORTE", 1: "SUR", 2: "ESTE", 3: "OESTE"}Maps integer phase IDs to direction strings
FFMPEG_BINResolved via imageio_ffmpegAbsolute path to the FFmpeg executable bundled by imageio-ffmpeg
NODE_PATHDetected via shutil.whichPath 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:
os.environ['OPENCV_FFMPEG_CAPTURE_OPTIONS'] = (
    'loglevel;quiet|rtsp_transport;tcp|http_persistent;0|'
    'reconnect;1|reconnect_streamed;1|reconnect_delay_max;5|'
    'fflags;nobuffer|flags;low_delay|probesize;32|analyzeduration;0|'
    'timeout;60000000|rw_timeout;60000000|'
    'user_agent;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
    '(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
)
os.environ['OPENCV_FFMPEG_OPEN_TIMEOUT'] = '60000'
os.environ['OPENCV_FFMPEG_READ_TIMEOUT'] = '60000'
os.environ['OPENCV_LOG_LEVEL'] = 'OFF'
These values are applied globally as soon as the module is imported and affect all OpenCV video captures opened during the session. The timeout values are expressed in milliseconds (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 Change DEFAULT_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:
# In app.py
DEFAULT_MODE = 'youtube'  # was 'idle'
Point to a custom YouTube stream Replace the bundled stream URL with your own live stream:
YOUTUBE_URL = "https://www.youtube.com/live/YOUR_STREAM_ID"
Adjust local video playback speed The default 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:
LOCAL_VIDEO_SPEED = 1.0  # real-time playback
MODEL_PATH in app.py is hardcoded to a developer’s Windows filesystem path:
C:\Users\Xande\important\The Predictors\Haklaton\The Predictors-traffic_reducer\traffic_reducer_dataset\modelo_entrenado\modelo_semaforo_ia.pkl
This path will not exist on any other machine. Update it to the correct absolute path before running Traffic Reducer, or the sklearn model will fail to load. The application handles this gracefully — it falls back to argmax-only mode using live vehicle counts — but the /predict endpoint will return a 500 error if the model is unavailable and live_mode is not used.

Build docs developers (and LLMs) love