Project name
- gst-video-lab
One-line summary
- A cross-machine CLI/TUI tool (Python) for sending, receiving, and measuring low-latency RTP video streams on macOS, built with GStreamer.
Goals
- Provide reproducible, scriptable tests for low-latency video streaming (RTP/RTCP) useful for real-time communications evaluation.
- Expose runtime controls (codec, bitrate, resolution, FEC, jitterbuffer) and live QoS metrics (RTT, packet loss, jitter, throughput).
- Produce logs and session exports (CSV/JSON) for offline analysis and CI-friendly regression tests.
- Be portable and easy to run on macOS (with optional Linux support).
Scope (MVP)
- Python CLI with optional TUI for interactive runs.
- Sender pipeline: avfvideosrc (macOS) → videoconvert → x264enc (or hardware fallback) → rtph264pay → udpsink.
- Receiver pipeline: udpsrc → rtpjitterbuffer → rtph264depay → avdec_h264 → videoconvert → appsink (display or headless).
- RTP header parsing via probes to compute bitrate, FPS, packet loss, and jitter. RTCP integration deferred (see Current limitations).
- Live display of metrics in TUI and periodic logging to CSV/JSON.
- Simple one-way and round-trip latency measurement using RTP payload timestamps (and optional echo responder mode).
- Configurable presets: low-latency (high fps, low bitrate), balanced, bandwidth-saving.
- README with install/run instructions and macOS-specific setup notes.
Out of scope (initial)
- Full WebRTC support (optional later).
- Complex NAT traversal (TURN/STUN) — not required for LAN tests.
- Production-grade media server components.
Technical stack
- Language: Python 3.11+.
- GStreamer bindings: PyGObject (GObject Introspection) + gst-python.
- UI: textual (TUI) for interactive; argparse-based CLI for scripted runs.
- Async: asyncio integrated with GLib MainLoop (GObject).
- Testing: pytest for unit tests, small integration helpers for local pipeline validation.
- CI: GitHub Actions for linting, unit tests, and simple headless pipeline checks.
- Optional native code: small C/C++ plugin only if needed for precise timestamping or payload instrumentation (kept isolated).
User personas
- Engineers evaluating real-time streaming performance.
- Developers learning GStreamer pipelines on macOS.
- QA teams needing reproducible test harnesses for codec/network experiments.
Key features & user flows
- Quick start (CLI)
- Command example: gst-video-lab send --dest 192.168.1.2 --codec h264 --preset low-latency gst-video-lab recv --listen-port 5004 --display
- Behavior: launches GStreamer pipeline, prints/updates metrics in terminal, logs to session file.
- Interactive TUI
- Panels:
- Controls: start/stop sender/receiver, choose preset, set dest/listen IPs and ports.
- Metrics: RTT, packet loss %, jitter (ms), fps, rx bitrate.
- Session log: recent RTCP events and errors.
- Actions: run latency test, save/export session, toggle FEC.
- Keyboard shortcuts for quick operations.
- Latency measurement modes
- Timestamp-in-payload:
- Sender stamps NTP or monotonic timestamp into RTP payload (small header).
- Receiver calculates one-way (if clocks synced) or round-trip via echo mode.
- Echo responder:
- Receiver/echo service sends back received RTP payloads to sender; sender computes RTT.
- Measurement outputs written to CSV/JSON with sample timestamps and percentiles.
Configuration
- Config file format: TOML or YAML (defaults in repo). Contains presets and pipeline param mappings.
- CLI flags override config values.
- Presets: low-latency, balanced, bandwidth-saving, high-quality.
Pipelines (examples to implement)
-
Sender (macOS, Python builder): avfvideosrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=360,framerate=30/1 ! x264enc tune=zerolatency bitrate=800 speed-preset=veryfast ! rtph264pay config-interval=1 pt=96 ! rtpbin.send_rtp_sink_0 -> udpsink host=DEST port=5004 (RTCP via udpsink/udpsrc pairs and rtpbin for RTCP)
-
Receiver (display): udpsrc port=5004 ! rtpjitterbuffer ! rtph264depay ! queue ! avdec_h264 ! videoconvert ! appsink
-
Receiver (headless/appsink): ... ! avdec_h264 ! appsink name=metrics_sink emit-signals=true
Metrics collection
- Decoder probe for FPS and decoded bitrate.
- RTP header probe on rtpjitterbuffer output for packet loss (sequence gaps), jitter (RFC 3550 A.8), and RTP bitrate.
- Future: parse RTCP Sender Reports from sender port 5005 for sender-side stats; construct Receiver Reports for RTT.
- Expose metrics via TUI and log to CSV/JSON each N seconds.
Logging & artifacts
- Session folder per run: logs/, metrics.csv, metrics.json, gst-debug logs (optional), sample recorded file (optional).
- Provide a small plotting script to turn CSV into PNG metrics graphs.
Security & privacy
- Default to LAN-only operations; require explicit IP to target remote hosts.
- No cloud upload or telemetry.
Acceptance criteria (MVP)
- CLI can start sender and receiver on two machines on same LAN and display live RTCP metrics.
- Latency measurement mode reports RTT percentiles (p50, p90, p99).
- Sessions can be exported to CSV/JSON and reproduced via CLI flags.
- README contains macOS install instructions and a short demo workflow producing screenshots.
Milestones & timeline (suggested)
- Week 1: Repo skeleton, environment docs, basic sender + receiver pipelines that run locally and exchange RTP.
- Week 2: Integrate rtpbin RTCP metrics; simple CLI start/stop; logging to JSON.
- Week 3: TUI skeleton showing live metrics; latency test mode and CSV export.
- Week 4: Presets, config file, CI pipeline and README polish; example recordings/screenshots and demo GIF.
Repository layout
- README.md
- specs.md (this file)
- LICENSE
- pyproject.toml / requirements.txt
- src/gst_video_lab/
- main.py
- cli.py (argparse entry points)
- tui.py (textual app)
- gst_pipelines.py (pipeline builders)
- session.py (logging, config, exporters)
- metrics.py (rtcp parsing, metric calculators)
- latency.py (timestamping & echo logic)
- utils.py (network helpers, clock sync hints)
- examples/
- quickstart.md
- sample-config.toml
- demo-commands.sh
- tests/
- unit/
- integration/ (small headless pipeline runs)
- docs/
- macos-setup.md
- pipeline-examples.md
- ci/
- workflow.yml
Development notes & macOS specifics
- Recommend installing GStreamer via Homebrew (gst-plugins-good/ugly/bad, gst-libav) and PyGObject via pip or brew as appropriate. Document exact commands in docs/macos-setup.md.
- macOS video source/sink: avfvideosrc / avfvideosink or videotoolbox-based encoders if available.
- Note sandboxing or permission prompts for camera/microphone—document granting camera access to terminal/runner if required.
Current limitations
- No rtpbin in receiver — PyGObject bug on macOS GStreamer 1.28.3: rtpbin's dynamic
recv_rtp_src_*pads are never created from Python (same pipeline works fromgst-launch-1.0). Workaround: direct pipeline + rtpjitterbuffer. Revisit if the bug is fixed in future GStreamer/PyGObject releases. - No RTCP metrics — jitter, RTT, and packet loss computed via RTP header probes instead of RTCP.
- macOS only — primary target; Linux support optional.
Extension ideas (post-MVP)
- WebRTC gateway mode for browser interop.
- Adaptive bitrate (ABR) with feedback-based switching.
- FEC and retransmit experiments.
- Small C plugin for precision timestamp injection or kernel-bypass optimizations.
- Dashboard web UI for centralized test orchestration.
Open questions (decisions made here; adjust later)
- Clock sync: assume no NTP sync in LAN; prefer RTT via echo for reliable latency.
- Codec: default H.264 (broad compatibility); provide VP8/AV1 as optional presets if encoders available.
- FEC: implement as a toggle, initially using simple RTP FEC payloads or packet duplication.
Next actions (concrete) ✓ done
- Create repo and add pyproject.toml, basic README and this specs.md.
- Implement minimal sender and receiver pipeline builders in gst_pipelines.py and a CLI to run them.
- Add metrics extraction from decoder probes and log to JSON.
- Build a minimal TUI that displays metrics and start/stop controls.