Tutorial 5 — Sports AI Live Streaming to YouTube with Jetson

Track every player, follow the ball, classify shots, and stream the fully annotated match live to YouTube — all from one Jetson board. No expensive broadcast equipment needed.

What you will learn

  • How to detect players with YOLOv8-pose in a sports context
  • How to track a ball using a custom model + Kalman filter
  • How to calculate ball speed using court homography
  • How to draw a live scoreboard overlay on video
  • How to push an RTMP stream to YouTube Live via GStreamer

Step 1 — Run the sports demo

cd ~/tutorials/05-sports-streaming
python3 sports_stream.py --source 0 --show

Step 2 — Stream to YouTube Live

# Get your stream key from YouTube Studio → Go Live → Stream Key
# Then run:
python3 sports_stream.py     --source 0     --stream-key YOUR_YOUTUBE_STREAM_KEY

Step 3 — The streaming pipeline

import cv2

STREAM_KEY = "YOUR_YOUTUBE_KEY"
RTMP       = f"rtmp://a.rtmp.youtube.com/live2/{STREAM_KEY}"
pipeline   = (
    "appsrc ! videoconvert ! "
    "nvv4l2h264enc bitrate=6000000 ! "
    "h264parse ! flvmux streamable=true ! "
    f"rtmpsink location={RTMP}"
)
out = cv2.VideoWriter(pipeline, cv2.CAP_GSTREAMER, 0, 30, (1920,1080))

Step 4 — Draw the overlay

def draw_overlay(frame, players, ball, score):
    # Draw player boxes
    for p in players:
        cv2.rectangle(frame, p.box_tl, p.box_br, (23,195,178), 2)
        cv2.putText(frame, f"#{p.jersey}", p.label_pos,
                    cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255,255,255), 2)
    # Draw ball + trail
    if ball:
        cv2.circle(frame, ball.center, 10, (0,255,255), -1)
        cv2.polylines(frame, [ball.trail], False, (0,200,200), 2)
    # Scoreboard
    draw_scoreboard(frame, score)
    return frame

Next: Tutorial 6 — Airplane Tracker with ADS-B | Back to Jetson Kit

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
0

Subtotal