go2rtc

repository·master·Indexed 11 days ago

https://github.com/alexxit/go2rtc

A camera streaming application supporting numerous formats and protocols. It provides low-latency streaming, on-the-fly transcoding via FFmpeg, and an HTTP/WebSocket API. It can be deployed as a standalone binary, a Docker container, or integrated into Home Assistant.

Tokens
57.5K
Snippets
215
Records
266
Agent score
94%

What's inside go2rtc

  1. H265 Support in go2rtc

    master
    go2rtc includes H265 (HEVC) payloader support. This implementation is based on the h265 branch of the pion/rtp library. This allows for the handling of H265 video streams within the go2rtc ecosystem, specifically for WebRTC transport.
  2. Use the MP4 module for streams and snapshots

    master

    The MP4 module in go2rtc provides three primary capabilities:

    1. MSE stream: Delivers fMP4 over WebSocket.
    2. Camera snapshots: Generates single-frame MP4 snapshots (useful for sending to services like Telegram).
    3. HTTP progressive streaming: Provides an MP4 file stream. Note that this format has a high start delay and may not work in all Safari browsers; in such cases, go2rtc automatically redirects to HLS/fMP4.

    API Endpoint Patterns

    • MP4 Snapshot (H264, H265): http://<go2rtc-ip>:1984/api/frame.mp4?src=<stream-name>

    • MP4 Stream (H264, H265, AAC): http://<go2rtc-ip>:1984/api/stream.mp4?src=<stream-name>

    • MP4 File/Record (Supports various codecs like H264, H265, AAC, OPUS, MP3, etc.): http://<go2rtc-ip>:1984/api/stream.mp4?src=<stream-name>

    http://192.168.1.123:1984/api/frame.mp4?src=camera1
  3. Use Pinggy for public tunnels

    master

    Pinggy is a service used to create public tunnels to your local services via the SSH protocol. In go2rtc, it is primarily used to expose the WebUI or camera streams (RTSP/HTTP) to the internet for testing purposes, such as verifying WebRTC connectivity or setting up HTTPS for two-way audio.

    Key Considerations:

    • Free Tier Limitations: Free accounts use random addresses that expire after one hour. This is intended for testing only.
    • Security Warning: Exposing go2rtc to the public internet without authorization can put your entire home network at risk. Use with extreme caution.
    • Protocols: Supports HTTP, TCP, and UDP.
  4. Projects using go2rtc

    master

    go2rtc is integrated into several major open-source and professional video surveillance projects, including:

    • Home Assistant (2024.11+)
    • Frigate (0.12+)
    • camera.ui (local-first professional surveillance platform)
    • Advanced Camera Card (Home Assistant custom card)
    • OpenIPC (alternative IP camera firmware)
    • wz_mini_hacks (Wyze camera firmware)
    • EufyP2PStream (Eufy camera RTSP support)
    • ioBroker.euSec (ioBroker adapter for Eufy)
    • MMM-go2rtc (MagicMirror² module)
    • ring-mqtt (Ring-to-MQTT bridge)
    • lightNVR
  5. Two-way audio support

    master

    Many protocols support two-way audio, allowing you to speak through the camera. This can be used in a web browser via WebRTC.

    Important Note: Browsers only grant microphone access for HTTPS sites.

    Supported protocols for two-way audio: doorbird, dvrip, exec, isapi, multitrans, ring, roborock, rtsp, tapo, tuya, webrtc, wyze, and xiaomi.

  6. Use Hikvision ISAPI for backchannel audio

    master

    The isapi:// source type in go2rtc supports only backchannel audio via the Hikvision ISAPI protocol.

    Because it does not provide a video stream, it should be used as a second source in conjunction with the RTSP protocol to enable two-way audio (audio from the client to the camera) while maintaining the video stream from RTSP.

    streams:
      hikvision1:
        - rtsp://admin:password@192.168.1.123:554/Streaming/Channels/101
        - isapi://admin:password@192.168.1.123:80/
  7. Use TCP sources with autodetection

    master

    go2rtc supports TCP streams and uses autodetection to identify the following formats:

    • adts: AAC audio with ADTS headers.
    • flv: Flash Video format.
    • h264: AVC/H.264 bitstream.
    • hevc: HEVC/H.265 bitstream.
    • mjpeg: Continuous JPEG frames (without HTTP headers).
    • mpegts: MPEG transport stream.
    • wav: WAV audio format.
    • yuv4mpegpipe: Raw YUV frame stream with YUV4MPEG header.
    streams:
      tcp_example: tcp://192.168.1.123:12345
  8. Extend the built-in viewer with video-rtc.js

    master

    Developers can build custom interfaces or extend the existing ones using www/video-rtc.js. This script handles complex streaming logic, including:

    • Technology Support: WebRTC (UDP/TCP) and WebSocket-based transport (MSE, HLS, MP4, or MJPEG).
    • Automatic Selection: It automatically selects the best technology based on stream codecs, browser capabilities, and network configuration.
    • Resource Management: Automatically stops streams when the browser tab is inactive or the player leaves the viewport.
    • Resilience: Includes automatic reconnection logic.

    Technology Selection Priority:

    1. Video + Audio is preferred over Video only.
    2. H265 is preferred over H264.
    3. WebRTC > MSE > HLS > MJPEG.
  9. Understand the WebRTC connection state lifecycle

    master

    When establishing a WebRTC connection in go2rtc, the process follows a specific sequence of state changes and signaling steps. Understanding this lifecycle is essential for debugging connection issues or implementing custom signaling logic.

    1. Offer Creation: The process begins with pc.CreateOffer().
    2. Local Description: The local description is set via pc.SetLocalDescription(offer).
    3. ICE Gathering: The OnICEGatheringStateChange event triggers gathering.
    4. Signaling State: The OnSignalingStateChange event moves to have-local-offer.
    5. ICE Completion: The OnICEGatheringStateChange event eventually reaches complete.
    6. Remote Description: The remote answer is applied via pc.SetRemoteDescription(answer).
    7. Stable Signaling: The OnSignalingStateChange event reaches the stable state.
    8. Connection Checking: The OnICEConnectionStateChange event moves to checking.
    9. Connection Established: The OnICEConnectionStateChange event reaches connected.
    1. offer = pc.CreateOffer()
    2. pc.SetLocalDescription(offer)
    3. OnICEGatheringStateChange: gathering
    4. OnSignalingStateChange: have-local-offer
    *. OnICEGatheringStateChange: complete
    5. pc.SetRemoteDescription(answer)
    6. OnSignalingStateChange: stable
    7. OnICEConnectionStateChange: checking
    8. OnICEConnectionStateChange: connected
  10. Understand ONVIF Profiles in go2rtc

    master

    go2rtc supports different ONVIF profiles which determine the capabilities available for a device. When configuring or using ONVIF devices, identify which profile your device supports to understand what features can be controlled:

    • Profile A: Used for access control configuration.
    • Profile C: Used for door control and event management.
    • Profile S: Used for basic video streaming, including video streaming and configuration.
    • Profile T: Used for advanced video streaming. This includes:
      • H.264 / H.265 video compression
      • Imaging settings
      • Motion alarm and tampering events
      • Metadata streaming
      • Bi-directional audio