Skip to content

Latest commit

 

History

History
118 lines (89 loc) · 3.27 KB

File metadata and controls

118 lines (89 loc) · 3.27 KB

People Detection → YouTube Live Stream — Setup Notes

System requirements

Requirement Notes
Python 3.9+ 3.10 or 3.11 recommended
FFmpeg Must be on $PATH
Webcam Any V4L2-compatible camera on Linux
GPU (optional) NVIDIA CUDA GPU speeds up inference significantly

Install FFmpeg

# Ubuntu / Debian
sudo apt update && sudo apt install ffmpeg

# macOS
brew install ffmpeg

# Windows (use winget or download from ffmpeg.org)
winget install ffmpeg

Python setup

# Create and activate a virtual environment (recommended)
python3 -m venv .venv
source .venv/bin/activate      # Windows: .venv\Scripts\activate

# Install Python dependencies
pip install -r requirements.txt

The first time you run the script, YOLOv8 will automatically download the model weights (~6 MB for yolov8n.pt) from the Ultralytics servers.


YouTube live stream setup

  1. Go to YouTube Studio → Go Live → Stream.
  2. Copy your Stream key (keep it secret — anyone with it can stream to your channel).
  3. Set the stream to Low-latency or Ultra low-latency in YouTube settings.
  4. YouTube requires the stream to be active for ~20–30 seconds before it appears live.

Running the script

# Minimal — streams from default camera (index 0)
python stream_people.py --stream-key YOUR_STREAM_KEY_HERE

# All options
python stream_people.py \
    --stream-key YOUR_STREAM_KEY_HERE \
    --camera 0 \           # camera device index
    --model yolov8n.pt \   # nano=fastest, yolov8s/m/l/x = more accurate but slower
    --fps 25 \             # frames per second sent to YouTube
    --conf 0.4 \           # detection confidence threshold (0.0–1.0)
    --preview              # show a local OpenCV window (adds slight latency)

Stop the stream at any time with Ctrl+C.


Model selection trade-offs

Model Size Speed Accuracy
yolov8n.pt ~6 MB Fastest Good
yolov8s.pt ~22 MB Fast Better
yolov8m.pt ~52 MB Medium Very good
yolov8l.pt ~87 MB Slow Excellent
yolov8x.pt ~137 MB Slowest Best

Start with yolov8n.pt (the default). If you have a GPU and need better accuracy, switch to yolov8s.pt or yolov8m.pt.


Troubleshooting

Problem Fix
Cannot open camera 0 Try --camera 1 or check ls /dev/video*
Low FPS / lag Use a smaller model (yolov8n) or lower --fps
FFmpeg pipe error Check your stream key and YouTube stream is enabled
Stream shows offline on YouTube Wait 20–30 s after starting; check stream health in YouTube Studio
CUDA not used Install torch with CUDA: pip install torch --index-url https://download.pytorch.org/whl/cu121
libx264 not found Reinstall FFmpeg with --enable-libx264 (most packaged versions include it)

Architecture overview

Webcam
  │  cv2.VideoCapture
  ▼
Frame (BGR numpy array)
  │  YOLOv8 inference  ──► filter class=person
  ▼
Annotated frame (bounding boxes + count overlay)
  │  frame.tobytes() → stdin pipe
  ▼
FFmpeg process
  │  libx264 encode → AAC silent audio
  ▼
RTMP push → rtmp://a.rtmp.youtube.com/live2/<stream-key>
  ▼
YouTube Live