# go2rtc
go2rtc is an ultimate camera streaming application supporting multiple protocols including RTSP, WebRTC, HomeKit, FFmpeg, RTMP, HTTP-FLV, MSE, HLS, MP4, and MJPEG. The application provides zero-dependency, zero-config streaming with the lowest possible latency, making it ideal for real-time video surveillance and smart home integrations. It serves as a media proxy and transcoder that can connect to various camera sources and deliver streams in multiple formats to different clients.
The core functionality centers around stream management and protocol conversion. go2rtc can receive streams from RTSP, RTMP, HTTP, ONVIF, HomeKit, proprietary camera protocols (Tapo, Tuya, Xiaomi, Wyze, Ring, etc.), and output them via WebRTC, RTSP, HLS, MP4, MJPEG, or other formats. It supports two-way audio for supported cameras, automatic codec negotiation between sources and clients, on-the-fly transcoding via FFmpeg, and integration with Home Assistant. The application runs as a standalone binary or Docker container with a built-in web interface on port 1984.
## Configuration
YAML-based configuration for defining streams and module settings.
The configuration file (`go2rtc.yaml`) defines camera streams, server settings, and module options. Streams can have multiple sources with different codecs that are automatically negotiated based on client capabilities.
```yaml
# go2rtc.yaml - Main configuration file
streams:
# RTSP camera with two-way audio (ONVIF backchannel)
dahua_camera:
- rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
- rtsp://admin:password@192.168.1.123/cam/realmonitor?channel=1&subtype=1#backchannel=0
# TP-Link Tapo camera with cloud password
tapo_camera: tapo://cloud-password@192.168.1.124
# FFmpeg transcoding for HLS-compatible output
transcoded_stream:
- rtsp://admin:password@192.168.1.125/stream1
- ffmpeg:transcoded_stream#video=h264#audio=aac
# USB webcam via FFmpeg device
usb_camera: ffmpeg:device?video=0&video_size=1280x720#video=h264
# API server configuration
api:
listen: ":1984" # HTTP API port
username: "admin" # Basic auth username
password: "secret" # Basic auth password
tls_listen: ":8443" # HTTPS port (optional)
# RTSP server configuration
rtsp:
listen: ":8554" # RTSP server port
username: "admin" # RTSP auth username
password: "secret" # RTSP auth password
default_query: "video&audio" # Default codec filter
# WebRTC configuration
webrtc:
listen: ":8555" # WebRTC TCP/UDP port
candidates:
- stun:8555 # Auto-detect external IP via STUN
# - 203.0.113.1:8555 # Static public IP
# FFmpeg transcoding templates
ffmpeg:
bin: ffmpeg # Path to ffmpeg binary
h264: "-codec:v libx264 -g:v 30 -preset:v superfast -tune:v zerolatency"
# HomeKit camera export
homekit:
dahua_camera:
pin: 19550224 # HomeKit pairing PIN
name: "Dahua Camera" # Display name in Home app
# Preload streams on startup (for faster initial connection)
preload:
dahua_camera: "video&audio"
```
## GET /api/streams - List All Streams
Retrieve information about all configured streams including active producers and consumers.
Returns a JSON object with stream names as keys, containing arrays of producers (sources) and consumers (clients) with codec information, connection state, and statistics.
```bash
# Get all streams status
curl http://localhost:1984/api/streams
# Response example:
{
"dahua_camera": {
"producers": [
{
"url": "rtsp://admin:***@192.168.1.123/cam/realmonitor?channel=1&subtype=0",
"medias": [
{"kind": "video", "codec": {"name": "H264", "clock_rate": 90000}},
{"kind": "audio", "codec": {"name": "PCMA", "clock_rate": 8000}}
],
"recv": {"bytes": 1234567, "packets": 5000},
"send": {"bytes": 0, "packets": 0}
}
],
"consumers": [
{
"url": "webrtc",
"remote_addr": "192.168.1.50:54321",
"recv": {"bytes": 0, "packets": 0},
"send": {"bytes": 987654, "packets": 4500}
}
]
},
"tapo_camera": {
"producers": [],
"consumers": []
}
}
# Get specific stream info
curl "http://localhost:1984/api/streams?src=dahua_camera"
```
## PUT /api/streams - Create Stream
Dynamically create a new stream at runtime without modifying the configuration file.
Creates a stream from any supported source URL. The stream persists until the application restarts or is explicitly deleted.
```bash
# Create RTSP stream
curl -X PUT "http://localhost:1984/api/streams?name=new_camera&src=rtsp://admin:password@192.168.1.200/stream1"
# Create stream with FFmpeg transcoding
curl -X PUT "http://localhost:1984/api/streams?name=transcoded&src=ffmpeg:rtsp://admin:password@192.168.1.200/stream1%23video=h264"
# Create stream from ONVIF camera (auto-discover RTSP URL)
curl -X PUT "http://localhost:1984/api/streams?name=onvif_cam&src=onvif://admin:password@192.168.1.201"
# Create stream from HTTP-MJPEG source
curl -X PUT "http://localhost:1984/api/streams?name=mjpeg_cam&src=http://192.168.1.202/video.mjpeg"
# Delete a stream
curl -X DELETE "http://localhost:1984/api/streams?src=new_camera"
```
## POST /api/webrtc - WebRTC/WHEP Streaming
Get a stream via WebRTC protocol using WHEP (WebRTC-HTTP Egress Protocol) standard.
Initiates a WebRTC session by exchanging SDP offers and answers. Supports both JSON and raw SDP formats. WebRTC provides the lowest latency streaming with automatic codec negotiation.
```bash
# Create WebRTC offer (using raw SDP)
curl -X POST "http://localhost:1984/api/webrtc?src=dahua_camera" \
-H "Content-Type: application/sdp" \
-d "v=0
o=- 0 0 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=msid-semantic: WMS *
m=video 9 UDP/TLS/RTP/SAVPF 96
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:xxxx
a=ice-pwd:xxxxxxxxxxxxxxxxxxxx
a=fingerprint:sha-256 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
a=setup:actpass
a=mid:0
a=recvonly
a=rtpmap:96 H264/90000
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=mid:1
a=recvonly
a=rtpmap:111 opus/48000/2"
# Response: SDP answer with server's media capabilities
# Using JSON format
curl -X POST "http://localhost:1984/api/webrtc?src=dahua_camera" \
-H "Content-Type: application/json" \
-d '{"type": "offer", "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\n..."}'
# Response:
{
"type": "answer",
"sdp": "v=0\r\no=- 0 0 IN IP4 192.168.1.100\r\n..."
}
```
## GET /api/stream.mp4 - MP4 Progressive Stream
Stream video in MP4 format via HTTP progressive download.
Provides an MP4 stream compatible with most video players. Supports codec filtering, duration limits, rotation, and scaling. Not supported on Safari browsers (use HLS instead).
```bash
# Basic MP4 stream
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera" -o stream.mp4
# Stream with duration limit (15 seconds)
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&duration=15" -o clip.mp4
# Stream with filename for download
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&duration=60&filename=recording.mp4" -O -J
# Stream with video rotation (90, 180, or 270 degrees)
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&rotate=90" -o rotated.mp4
# Stream with scaling
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&scale=1280:720" -o scaled.mp4
# Stream with codec filter (H264 video only, no audio)
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&video=h264" -o video_only.mp4
# Stream with FLAC audio (for PCMA/PCMU sources)
curl "http://localhost:1984/api/stream.mp4?src=dahua_camera&mp4=flac" -o with_pcm.mp4
# Play stream directly with ffplay
ffplay "http://localhost:1984/api/stream.mp4?src=dahua_camera"
# Record with VLC
vlc "http://localhost:1984/api/stream.mp4?src=dahua_camera" --sout file/mp4:recording.mp4
```
## GET /api/stream.m3u8 - HLS Streaming
Stream video using HTTP Live Streaming (HLS) protocol.
HLS is supported by Safari, iOS devices, and most streaming platforms. Provides adaptive bitrate streaming with TS or fMP4 segments. Higher latency than WebRTC but wider compatibility.
```bash
# Basic HLS stream (TS segments, H264 only)
curl "http://localhost:1984/api/stream.m3u8?src=dahua_camera"
# Response: HLS master playlist
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=1000000,CODECS="avc1.64001F"
hls/playlist.m3u8?id=DvmHdd9w
# HLS with fMP4 segments (supports H265 and AAC)
curl "http://localhost:1984/api/stream.m3u8?src=dahua_camera&mp4"
# HLS with FLAC audio support
curl "http://localhost:1984/api/stream.m3u8?src=dahua_camera&mp4=flac"
# Play HLS stream in VLC
vlc "http://localhost:1984/api/stream.m3u8?src=dahua_camera"
# Play in ffplay
ffplay "http://localhost:1984/api/stream.m3u8?src=dahua_camera"
# HTML5 video player (use hls.js for non-Safari browsers)
#
#
#
```
## GET /api/frame.jpeg - JPEG Snapshot
Capture a single frame snapshot from a stream in JPEG format.
Extracts a frame from the video stream. Requires MJPEG codec in the source or FFmpeg transcoding. Supports resizing, rotation, and hardware acceleration.
```bash
# Basic snapshot
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera" -o snapshot.jpg
# Snapshot with resize (width only, maintains aspect ratio)
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera&width=640" -o thumb.jpg
# Snapshot with exact dimensions
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera&w=320&h=240" -o small.jpg
# Snapshot with rotation
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera&rotate=90" -o rotated.jpg
# Snapshot with hardware acceleration (Intel QuickSync)
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera&hw=vaapi" -o hw_snap.jpg
# Snapshot from RTSP URL directly (creates temporary stream)
curl "http://localhost:1984/api/frame.jpeg?src=rtsp://admin:password@192.168.1.123/stream1" -o direct.jpg
# Cached snapshot (returns cached version if less than 10 seconds old)
curl "http://localhost:1984/api/frame.jpeg?src=dahua_camera&cache=10s" -o cached.jpg
# For streams without MJPEG, add FFmpeg transcoding source:
# streams:
# camera_with_snapshot:
# - rtsp://admin:password@192.168.1.123/stream1
# - ffmpeg:camera_with_snapshot#video=mjpeg
```
## GET /api/stream.mjpeg - MJPEG Streaming
Stream video as Motion JPEG over HTTP multipart response.
MJPEG streaming works in any browser without JavaScript. Lower compression efficiency than H264 but widely compatible. Requires MJPEG codec in source.
```bash
# Basic MJPEG stream
curl "http://localhost:1984/api/stream.mjpeg?src=dahua_camera" --output -
# View in browser: http://localhost:1984/api/stream.mjpeg?src=dahua_camera
# HTML img tag (auto-refreshing in supported browsers)
#
# For H264 streams, add MJPEG transcoding:
# streams:
# mjpeg_stream:
# - rtsp://admin:password@192.168.1.123/stream1
# - ffmpeg:mjpeg_stream#video=mjpeg
# Stream ASCII art to terminal
curl "http://localhost:1984/api/stream.ascii?src=dahua_camera"
# ASCII with 256 colors
curl "http://localhost:1984/api/stream.ascii?src=dahua_camera&color=256"
# ASCII with background colors and space characters
curl "http://localhost:1984/api/stream.ascii?src=dahua_camera&back=256&text=%20"
```
## WebSocket API - /api/ws
Real-time bidirectional communication for WebRTC, MSE, HLS, and MJPEG streaming.
The WebSocket endpoint enables browser-based streaming with automatic technology selection based on browser capabilities and stream codecs.
```javascript
// JavaScript WebRTC client example
const ws = new WebSocket('ws://localhost:1984/api/ws?src=dahua_camera');
const pc = new RTCPeerConnection({
iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
});
pc.addTransceiver('video', {direction: 'recvonly'});
pc.addTransceiver('audio', {direction: 'recvonly'});
pc.ontrack = (event) => {
document.getElementById('video').srcObject = event.streams[0];
};
pc.onicecandidate = (event) => {
if (event.candidate) {
ws.send(JSON.stringify({
type: 'webrtc/candidate',
value: event.candidate.candidate
}));
}
};
ws.onopen = async () => {
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
ws.send(JSON.stringify({
type: 'webrtc/offer',
value: offer.sdp
}));
};
ws.onmessage = async (event) => {
const msg = JSON.parse(event.data);
if (msg.type === 'webrtc/answer') {
await pc.setRemoteDescription({type: 'answer', sdp: msg.value});
} else if (msg.type === 'webrtc/candidate' && msg.value) {
await pc.addIceCandidate({candidate: msg.value});
}
};
// MSE (Media Source Extensions) streaming
const wsMSE = new WebSocket('ws://localhost:1984/api/ws?src=dahua_camera');
wsMSE.binaryType = 'arraybuffer';
wsMSE.onopen = () => {
// Request MSE stream with supported codecs
wsMSE.send(JSON.stringify({
type: 'mse',
value: 'avc1.640029,avc1.64002A,hvc1.1.6.L153.B0,mp4a.40.2,mp4a.40.5,flac,opus'
}));
};
wsMSE.onmessage = (event) => {
if (typeof event.data === 'string') {
const msg = JSON.parse(event.data);
if (msg.type === 'mse') {
// Initialize MediaSource with received MIME type
const mediaSource = new MediaSource();
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', () => {
const sourceBuffer = mediaSource.addSourceBuffer(msg.value);
// Subsequent binary messages are media data
});
}
} else {
// Append binary data to source buffer
sourceBuffer.appendBuffer(event.data);
}
};
```
## POST /api/streams - Stream to Camera (Two-Way Audio)
Send audio or media to a camera with speaker support.
Enables playing audio files, TTS, or live streams on cameras with two-way audio capability. Useful for intercom functionality and announcements.
```bash
# Play MP3 file to camera speaker (transcoded to PCMA)
curl -X POST "http://localhost:1984/api/streams?dst=tapo_camera&src=ffmpeg:http://example.com/doorbell.mp3%23audio=pcma%23input=file"
# Play local file
curl -X POST "http://localhost:1984/api/streams?dst=tapo_camera&src=ffmpeg:/media/alert.wav%23audio=pcma%23input=file"
# Stream live internet radio
curl -X POST "http://localhost:1984/api/streams?dst=tapo_camera&src=ffmpeg:http://stream.example.com/radio.mp3%23audio=pcma"
# Text-to-speech using FFmpeg flite
curl -X POST "http://localhost:1984/api/streams?dst=tapo_camera&src=ffmpeg:%23input=-f%20lavfi%20-i%20%22flite=text='Someone%20at%20the%20door'%22%23audio=pcma"
# Stop active playback
curl -X POST "http://localhost:1984/api/streams?dst=tapo_camera&src="
# Using the helper endpoint for TTS
curl -X POST "http://localhost:1984/api/ffmpeg?dst=tapo_camera&text=Hello%20World"
# Play file via helper endpoint
curl -X POST "http://localhost:1984/api/ffmpeg?dst=tapo_camera&file=http://example.com/sound.mp3"
# Play live stream via helper endpoint
curl -X POST "http://localhost:1984/api/ffmpeg?dst=tapo_camera&live=http://stream.example.com/audio"
```
## Discovery APIs - Device Auto-Detection
Discover cameras and devices on the local network.
Various discovery endpoints help find ONVIF cameras, DVRIP devices, USB cameras, Home Assistant cameras, and other supported sources.
```bash
# Discover ONVIF cameras on local network
curl "http://localhost:1984/api/onvif"
# Response:
{
"streams": [
{"name": "ONVIF Camera 1", "url": "onvif://admin:password@192.168.1.100:80"},
{"name": "ONVIF Camera 2", "url": "onvif://admin:password@192.168.1.101:2020"}
]
}
# Get ONVIF camera profiles
curl "http://localhost:1984/api/onvif?src=onvif://admin:password@192.168.1.100"
# Response with available streams/profiles
# Discover DVRIP/XMeye cameras
curl "http://localhost:1984/api/dvrip"
# Discover USB/V4L2 cameras (Linux)
curl "http://localhost:1984/api/v4l2"
# Discover FFmpeg devices (Windows/Mac/Linux)
curl "http://localhost:1984/api/ffmpeg/devices"
# Check available hardware acceleration
curl "http://localhost:1984/api/ffmpeg/hardware"
# Response:
{
"streams": [
{"name": "Intel QuickSync", "url": "vaapi"},
{"name": "NVIDIA NVENC", "url": "cuda"}
]
}
# Discover HomeKit cameras
curl "http://localhost:1984/api/discovery/homekit"
# Discover Home Assistant cameras
curl "http://localhost:1984/api/hass"
# Discover Ring cameras (requires authentication)
curl "http://localhost:1984/api/ring?email=user@example.com&password=secret"
# Discover Tuya cameras
curl "http://localhost:1984/api/tuya?region=openapi.tuyaus.com&email=user@example.com&password=secret"
```
## RTSP Server - rtsp://host:8554/stream
Access any stream via standard RTSP protocol.
The built-in RTSP server allows consuming streams using RTSP clients like VLC, FFmpeg, or NVR systems. Supports authentication and codec filtering via query parameters.
```bash
# Play RTSP stream in VLC
vlc rtsp://localhost:8554/dahua_camera
# Play with ffplay (low latency settings)
ffplay -fflags nobuffer -flags low_delay "rtsp://localhost:8554/dahua_camera"
# Record RTSP stream with ffmpeg
ffmpeg -i rtsp://localhost:8554/dahua_camera -c copy -t 60 recording.mp4
# RTSP with authentication (if configured)
ffplay "rtsp://admin:password@localhost:8554/dahua_camera"
# RTSP with codec filter (MP4-compatible: H264/H265 + AAC)
ffplay "rtsp://localhost:8554/dahua_camera?mp4"
# RTSP with specific video codec
ffplay "rtsp://localhost:8554/dahua_camera?video=h264"
# RTSP with multiple audio tracks
ffplay "rtsp://localhost:8554/dahua_camera?video&audio=all"
# Push stream to go2rtc via RTSP
ffmpeg -re -i video.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://localhost:8554/incoming_stream
# RTSP URL for Home Assistant / Frigate
# rtsp://192.168.1.100:8554/dahua_camera?mp4
```
## FFmpeg Source Integration
Use FFmpeg for transcoding, file playback, device capture, and format conversion.
FFmpeg source provides powerful transcoding capabilities, hardware acceleration, and support for formats not natively supported by go2rtc.
```yaml
# go2rtc.yaml - FFmpeg source examples
streams:
# Transcode H265 to H264 for WebRTC compatibility
h265_to_h264:
- rtsp://admin:password@192.168.1.123/stream1
- ffmpeg:h265_to_h264#video=h264#hardware
# Add OPUS audio transcoding for WebRTC
with_opus_audio:
- rtsp://admin:password@192.168.1.123/stream1
- ffmpeg:with_opus_audio#audio=opus
# Rotate video 90 degrees
rotated_camera: ffmpeg:rtsp://admin:password@192.168.1.123/stream1#video=h264#rotate=90
# Resize video
scaled_camera: ffmpeg:rtsp://admin:password@192.168.1.123/stream1#video=h264#width=1280#height=720
# Play local file in loop
file_stream: ffmpeg:/media/video.mp4#video=copy#audio=copy
# HLS source
hls_stream: ffmpeg:https://example.com/stream/playlist.m3u8#video=copy
# USB webcam (Windows)
webcam_win: ffmpeg:device?video=0#video=h264
# USB webcam (Linux)
webcam_linux: ffmpeg:device?video=/dev/video0&video_size=1280x720#video=h264
# USB webcam (macOS) with FaceTime camera
webcam_mac: ffmpeg:device?video=0&audio=1&video_size=1280x720&framerate=30#video=h264#audio=pcma
# Add timestamp overlay (CPU intensive)
timestamped: ffmpeg:rtsp://admin:password@192.168.1.123/stream1#video=h264#raw=-vf drawtext=text='%{localtime}':fontsize=24:fontcolor=white:x=10:y=10
# Hardware-accelerated transcoding (Intel QuickSync)
hw_transcode: ffmpeg:rtsp://admin:password@192.168.1.123/stream1#video=h264#hardware=vaapi
# Custom FFmpeg input template
custom_input: ffmpeg:rtsp://192.168.1.123/stream1#input=-timeout 10000000 -rtsp_transport tcp -i {input}#video=copy
# Custom FFmpeg templates
ffmpeg:
bin: /usr/bin/ffmpeg
h264: "-codec:v libx264 -g:v 30 -preset:v superfast -tune:v zerolatency -profile:v main -level:v 4.1"
opus: "-codec:a libopus -ar 48000 -ac 2"
```
## Expr Source - Dynamic Stream URLs
Generate stream URLs dynamically using expressions and HTTP requests.
The expr source uses a JavaScript-like expression language to fetch credentials, parse responses, and construct stream URLs at runtime.
```yaml
# go2rtc.yaml - Expr source examples
streams:
# Simple URL construction
dynamic_camera: |
expr:
let host = "192.168.1.123";
let user = "admin";
let pass = "password";
"rtsp://" + user + ":" + pass + "@" + host + "/stream1"
# Fetch token from API and construct URL
token_auth_camera: |
expr:
let api = "https://api.example.com";
let r = fetch(api + "/auth/token", {
method: "POST",
data: {username: "user", password: "pass"}
});
let token = r.json().access_token;
"rtsp://token:" + token + "@192.168.1.123/stream1"
# Parse HLS URL from webpage
parsed_hls: |
expr:
let html = fetch("https://example.com/live").text;
let url = match(html, "https://[^\"]+\\.m3u8")[0];
"ffmpeg:" + url + "#video=copy"
# Multi-step authentication
secured_stream: |
expr:
let host = "192.168.1.123";
var r1 = fetch("http://" + host + "/login", {
method: "POST",
data: {user: "admin", pass: "secret"}
});
var r2 = fetch("http://" + host + "/api/stream/url").json();
r2.rtsp_url
# Configure camera settings before streaming
configured_camera: |
expr:
let host = "admin:password@192.168.1.123";
var r = fetch("http://" + host + "/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Video.Compression=H.264");
"rtsp://" + host + "/cam/realmonitor?channel=1&subtype=0"
```
## HomeKit Integration
Export cameras to Apple HomeKit or proxy existing HomeKit cameras.
HomeKit module allows using go2rtc cameras in Apple Home app and bridging HomeKit cameras for RTSP/WebRTC access.
```yaml
# go2rtc.yaml - HomeKit configuration
streams:
# Regular camera to export to HomeKit
front_door:
- rtsp://admin:password@192.168.1.123/stream1
- ffmpeg:front_door#video=h264#audio=opus # HomeKit requires H264+OPUS
# Proxy existing HomeKit camera (paired via WebUI)
homekit_camera:
- homekit://A1:B2:C3:D4:E5:F6:12345678@192.168.1.124
- ffmpeg:homekit_camera#audio=aac#audio=opus
homekit:
# Export camera to HomeKit
front_door:
pin: 19550224 # Pairing PIN (shown in Home app)
name: "Front Door" # Camera name in Home app
# Proxy HomeKit camera back to HomeKit (maintains features)
homekit_camera:
pin: 19550224
```
```bash
# Discover HomeKit cameras for pairing
curl "http://localhost:1984/api/discovery/homekit"
# Pair HomeKit camera via API
curl -X POST "http://localhost:1984/api/homekit?id=aqara_camera&src=homekit://A1:B2:C3:D4:E5:F6@192.168.1.124&pin=12345678"
# Get HomeKit server status
curl "http://localhost:1984/api/homekit"
# Get HomeKit accessories
curl "http://localhost:1984/api/homekit/accessories?id=front_door"
# Unpair HomeKit camera
curl -X DELETE "http://localhost:1984/api/homekit?id=aqara_camera"
```
## WebTorrent Sharing
Share streams securely over the internet without port forwarding.
WebTorrent enables peer-to-peer streaming through NAT using WebRTC data channels. Streams can be shared with anyone using a generated link.
```bash
# Create WebTorrent share for a stream
curl -X POST "http://localhost:1984/api/webtorrent?src=dahua_camera"
# Response:
{
"share": "AKDypPy4zz",
"pwd": "H0Km1HLTTP"
}
# Share URL: https://go2rtc.org/webtorrent/#share=AKDypPy4zz&pwd=H0Km1HLTTP&media=video+audio
# Get existing share info
curl "http://localhost:1984/api/webtorrent?src=dahua_camera"
# List all shares
curl "http://localhost:1984/api/webtorrent"
# Delete share
curl -X DELETE "http://localhost:1984/api/webtorrent?src=dahua_camera"
```
```yaml
# go2rtc.yaml - Permanent WebTorrent shares
webtorrent:
shares:
my-secure-share: # Share name (must be unique globally)
pwd: my-secret-pass # Access password
src: dahua_camera # Source stream name
streams:
# Consume WebTorrent stream from another go2rtc instance
remote_camera: webtorrent:?share=AKDypPy4zz&pwd=H0Km1HLTTP
```
## Application Management APIs
Control application lifecycle, configuration, and debugging.
Administrative APIs for managing the go2rtc application including configuration, logging, and graceful shutdown.
```bash
# Get application info
curl "http://localhost:1984/api"
# Response:
{
"config_path": "/config/go2rtc.yaml",
"host": "192.168.1.100:1984",
"rtsp": {
"listen": ":8554",
"default_query": "video&audio"
},
"version": "1.9.14"
}
# Get current configuration
curl "http://localhost:1984/api/config"
# Update configuration (merge)
curl -X PATCH "http://localhost:1984/api/config" \
-H "Content-Type: application/yaml" \
-d 'streams:
new_camera: rtsp://admin:password@192.168.1.200/stream1'
# Replace entire configuration
curl -X POST "http://localhost:1984/api/config" \
-H "Content-Type: application/yaml" \
-d @go2rtc.yaml
# Get application logs
curl "http://localhost:1984/api/log"
# Clear log buffer
curl -X DELETE "http://localhost:1984/api/log"
# Get supported URL schemes
curl "http://localhost:1984/api/schemes"
# Response: ["rtsp", "rtmp", "http", "https", "onvif", "tapo", "ffmpeg", ...]
# Graceful shutdown
curl -X POST "http://localhost:1984/api/exit"
# Shutdown with exit code
curl -X POST "http://localhost:1984/api/exit?code=0"
# Restart application (daemon mode)
curl -X POST "http://localhost:1984/api/restart"
# Debug: view stream graph (Graphviz DOT format)
curl "http://localhost:1984/api/streams.dot?src=dahua_camera"
# Debug: view goroutine stack
curl "http://localhost:1984/api/stack"
```
## Summary
go2rtc serves as a universal camera streaming hub that bridges different protocols, codecs, and platforms. Primary use cases include: providing WebRTC/MSE streams for web browsers with minimal latency, acting as an RTSP proxy for NVR systems and Home Assistant, enabling HomeKit integration for non-HomeKit cameras, transcoding incompatible codecs via FFmpeg, providing JPEG snapshots for automation and notifications, and enabling two-way audio for intercoms and announcements.
Integration patterns typically involve deploying go2rtc alongside smart home platforms (Home Assistant, Frigate), configuring camera sources in YAML with appropriate transcoding for target clients, using the HTTP API for dynamic stream management, and leveraging WebSocket for real-time browser streaming. For production deployments, consider enabling authentication on the API and RTSP servers, configuring HTTPS for WebRTC microphone access, setting up appropriate WebRTC candidates for external access, and using preload for frequently accessed streams to minimize connection latency.