skrashevich/go2rtc

By skrashevich

Updated about 2 years ago

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, MJPEG, HomeKit

Image
Networking
Internet of things
Developer tools
0

10K+

skrashevich/go2rtc repository overview

go2rtc

Ultimate camera streaming application with support RTSP, WebRTC, HomeKit, FFmpeg, RTMP, etc.

Inspired by:


Fast start

  1. Download binary or use Docker or Home Assistant Add-on or Integration
  2. Open web interface: http://localhost:1984/

Optionally:

Developers:

go2rtc: Binary

Download binary for your OS from latest release:

  • go2rtc_win64.zip - Windows 64-bit
  • go2rtc_win32.zip - Windows 32-bit
  • go2rtc_linux_amd64 - Linux 64-bit
  • go2rtc_linux_i386 - Linux 32-bit
  • go2rtc_linux_arm64 - Linux ARM 64-bit (ex. Raspberry 64-bit OS)
  • go2rtc_linux_arm - Linux ARM 32-bit (ex. Raspberry 32-bit OS)
  • go2rtc_linux_mipsel - Linux MIPS (ex. Xiaomi Gateway 3)
  • go2rtc_mac_amd64.zip - Mac Intel 64-bit
  • go2rtc_mac_arm64.zip - Mac ARM 64-bit

Don't forget to fix the rights chmod +x go2rtc_xxx_xxx on Linux and Mac.

go2rtc: Docker

Container alexxit/go2rtc with support amd64, 386, arm64, arm. This container is the same as Home Assistant Add-on, but can be used separately from Home Assistant. Container has preinstalled FFmpeg, Ngrok and Python.

go2rtc: Home Assistant Add-on

  1. Install Add-On:
    • Settings > Add-ons > Plus > Repositories > Add https://github.com/AlexxIT/hassio-addons
    • go2rtc > Install > Start
  2. Setup Integration
go2rtc: Home Assistant Integration

WebRTC Camera custom component can be used on any Home Assistant installation, including HassWP on Windows. It can automatically download and use the latest version of go2rtc. Or it can connect to an existing version of go2rtc. Addon installation in this case is optional.

Configuration

  • by default go2rtc will search go2rtc.yaml in the current work dirrectory
  • api server will start on default 1984 port (TCP)
  • rtsp server will start on default 8554 port (TCP)
  • webrtc will use port 8555 (TCP/UDP) for connections
  • ffmpeg will use default transcoding options

Configuration options and a complete list of settings can be found in the wiki.

Available modules:

Module: Streams

go2rtc support different stream source types. You can config one or multiple links of any type as stream source.

Available source types:

Read more about incoming sources

Two way audio

Supported for sources:

Two way audio can be used in browser with WebRTC technology. The browser will give access to the microphone only for HTTPS sites (read more).

go2rtc also support play audio files and live streams on this cameras.

Source: RTSP
streams:
  sonoff_camera: rtsp://rtsp:[email protected]/av_stream/ch0
  dahua_camera:
    - rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
    - rtsp://admin:[email protected]/cam/realmonitor?channel=1&subtype=1
  amcrest_doorbell:
    - rtsp://username:[email protected]:554/cam/realmonitor?channel=1&subtype=0#backchannel=0
  unify_camera: rtspx://192.168.1.123:7441/fD6ouM72bWoFijxK
  glichy_camera: ffmpeg:rstp://username:[email protected]/live/ch00_1 

Recommendations

  • Amcrest Doorbell users may want to disable two way audio, because with an active stream you won't have a call button working. You need to add #backchannel=0 to the end of your RTSP link in YAML config file
  • Dahua Doorbell users may want to change backchannel audio codec
  • Unify users may want to disable HTTPS verification. Use rtspx:// prefix instead of rtsps://. And don't use ?enableSrtp suffix
  • TP-Link Tapo users may skip login and password, because go2rtc support login without them
  • If your camera has two RTSP links - you can add both of them as sources. This is useful when streams has different codecs, as example AAC audio with main stream and PCMU/PCMA audio with second stream
  • If the stream from your camera is glitchy, try using ffmpeg source. It will not add CPU load if you won't use transcoding
  • If the stream from your camera is very glitchy, try to use transcoding with ffmpeg source
Source: RTMP

You can get stream from RTMP server, for example Frigate.

streams:
  rtmp_stream: rtmp://192.168.1.123/live/camera1
Source: HTTP

Support Content-Type:

  • HTTP-FLV (video/x-flv) - same as RTMP, but over HTTP
  • HTTP-JPEG (image/jpeg) - camera snapshot link, can be converted by go2rtc to MJPEG stream
  • HTTP-MJPEG (multipart/x) - simple MJPEG stream over HTTP
  • MPEG-TS (video/mpeg) - legacy streaming format
streams:
  # [HTTP-FLV] stream in video/x-flv format
  http_flv: http://192.168.1.123:20880/api/camera/stream/780900131155/657617
  
  # [JPEG] snapshots from Dahua camera, will be converted to MJPEG stream
  dahua_snap: http://admin:[email protected]/cgi-bin/snapshot.cgi?channel=1

  # [MJPEG] stream will be proxied without modification
  http_mjpeg: https://mjpeg.sanford.io/count.mjpeg

PS. Dahua camera has bug: if you select MJPEG codec for RTSP second stream - snapshot won't work.

Source: FFmpeg

You can get any stream or file or device via FFmpeg and push it to go2rtc. The app will automatically start FFmpeg with the proper arguments when someone starts watching the stream.

  • FFmpeg preistalled for Docker and Hass Add-on users
  • Hass Add-on users can target files from /media folder

Format: ffmpeg:{input}#{param1}#{param2}#{param3}. Examples:

streams:
  # [FILE] all tracks will be copied without transcoding codecs
  file1: ffmpeg:/media/BigBuckBunny.mp4

  # [FILE] video will be transcoded to H264, audio will be skipped
  file2: ffmpeg:/media/BigBuckBunny.mp4#video=h264

  # [FILE] video will be copied, audio will be transcoded to pcmu
  file3: ffmpeg:/media/BigBuckBunny.mp4#video=copy#audio=pcmu

  # [HLS] video will be copied, audio will be skipped
  hls: ffmpeg:https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/gear5/prog_index.m3u8#video=copy

  # [MJPEG] video will be transcoded to H264
  mjpeg: ffmpeg:http://185.97.122.128/cgi-bin/faststream.jpg#video=h264

  # [RTSP] video with rotation, should be transcoded, so select H264
  rotate: ffmpeg:rtsp://rtsp:[email protected]/av_stream/ch0#video=h264#rotate=90

All trascoding formats has built-in templates: h264, h265, opus, pcmu, pcmu/16000, pcmu/48000, pcma, pcma/16000, pcma/48000, aac, aac/16000.

But you can override them via YAML config. You can also add your own formats to config and use them with source params.

ffmpeg:
  bin: ffmpeg  # path to ffmpeg binary
  h264: "-codec:v libx264 -g:v 30 -preset:v superfast -tune:v zerolatency -profile:v main -level:v 4.1"
  mycodec: "-any args that support ffmpeg..."
  myinput: "-fflags nobuffer -flags low_delay -timeout 5000000 -i {input}"
  • You can use video and audio params multiple times (ex. #video=copy#audio=copy#audio=pcmu)
  • You can use go2rtc stream name as ffmpeg input (ex. ffmpeg:camera1#video=h264)
  • You can use rotate params with 90, 180, 270 or -90 values, important with transcoding (ex. #video=h264#rotate=90)
  • You can use width and/or height params, important with transcoding (ex. #video=h264#width=1280)
  • You can use raw param for any additional FFmpeg arguments (ex. #raw=-vf transpose=1)
  • You can use input param to override default input template (ex. #input=rtsp/udp will change RTSP transport from TCP to UDP+TCP)
    • You can use raw input value (ex. #input=-timeout 5000000 -i {input})
    • You can add your own input templates

Read more about encoding hardware acceleration.

Source: FFmpeg Device

You can get video from any USB-camera or Webcam as RTSP or WebRTC stream. This is part of FFmpeg integration.

  • check available devices in Web interface
  • resolution and framerate must be supported by your camera!
  • for Linux supported only video for now
  • for macOS you can stream Facetime camera or whole Desktop!
  • for macOS important to set right framerate
streams:
  linux_usbcam:   ffmpeg:device?video=0&resolution=1280x720#video=h264
  windows_webcam: ffmpeg:device?video=0#video=h264
  macos_facetime: ffmpeg:device?video=0&audio=1&resolution=1280x720&framerate=30#video=h264#audio=pcma
Source: Exec

FFmpeg source just a shortcut to exec source. You can get any stream or file or device via FFmpeg or GStreamer and push it to go2rtc via RTSP protocol:

streams:
  stream1: exec:ffmpeg -hide_banner -re -stream_loop -1 -i /media/BigBuckBunny.mp4 -c copy -rtsp_transport tcp -f rtsp {output}
Source: Echo

Some sources may have a dynamic link. And you will need to get it using a bash or python script. Your script should echo a link to the source. RTSP, FFmpeg or any of the supported sources.

Docker and Hass Add-on users has preinstalled python3, curl, jq.

Check examples in wiki.

streams:
  apple_hls: echo:python3 hls.py https://developer.apple.com/streaming/examples/basic-stream-osx-ios5.html
Source: HomeKit

Important:

  • You can use HomeKit Cameras without Apple devices (iPhone, iPad, etc.), it's just a yet another protocol
  • HomeKit device can be paired with only one ecosystem. So, if you have paired it to an iPhone (Apple Home) - you can't pair it with Home Assistant or go2rtc. Or if you have paired it to go2rtc - you can't pair it with iPhone
  • HomeKit device should be in same network with working mDNS between device and go2rtc

go2rtc support import paired HomeKit devices from Home Assistant. So you can use HomeKit camera with Hass and go2rtc simultaneously. If you using Hass, I recommend pairing devices with it, it will give you more options.

You can pair device with go2rtc on the HomeKit page. If you can't see your devices - reload the page. Also try reboot your HomeKit device (power off). If you still can't see it - you have a problems with mDNS.

If you see a device but it does not have a pair button - it is paired to some ecosystem (Apple Home, Home Assistant, HomeBridge etc). You need to delete device from that ecosystem, and it will be available for pairing. If you cannot unpair device, you will have to reset it.

Important:

  • HomeKit audio uses very non-standard AAC-ELD codec with very non-standard params and specification violation
  • Audio can be transcoded by ffmpeg source with #async option
  • Audio can be played by ffplay with -use_wallclock_as_timestamps 1 -async 1 options
  • Audio can't be played in VLC and probably any other player

Recommended settings for using HomeKit Camera with WebRTC, MSE, MP4, RTSP:

streams:
  aqara_g3:
    - hass:Camera-Hub-G3-AB12
    - ffmpeg:aqara_g3#audio=aac#audio=opus#async

RTSP link with "normal" audio for any player: rtsp://192.168.1.123:8554/aqara_g3?video&audio=aac

This source is in active development! Tested only with Aqara Camera Hub G3 (both EU and CN versions).

Source: DVRIP

Other names: DVR-IP, NetSurveillance, Sofia protocol (NETsurveillance ActiveX plugin XMeye SDK).

  • you can skip username, password, port, channel and subtype if they are default
  • setup separate streams for different channels
  • use subtype=0 for Main stream, and subtype=1 for Extra1 stream
  • only the TCP protocol is supported
streams:
  camera1: dvrip://username:[email protected]:34567?channel=0&subtype=0
Source: Tapo

TP-Link Tapo proprietary camera protocol with two way audio support.

  • stream quality is the same as RTSP protocol
  • use the cloud password, this is not the RTSP password! you do not need to add a login!
  • you can also use UPPERCASE MD5 hash from your cloud password with admin username
streams:
  # cloud password without username
  camera1: tapo://[email protected]
  # admin username and UPPERCASE MD5 cloud-password hash
  camera2: tapo://admin:[email protected]
Source: Ivideon

Support public cameras from service Ivideon.

streams:
  quailcam: ivideon:100-tu5dkUPct39cTp9oNEN2B6/0
Source: Hass

Support import camera links from Home Assistant config files:

hass:
  config: "/config"  # skip this setting if you Hass Add-on user

streams:
  generic_camera: hass:Camera1  # Settings > Integrations > Integration Name
  aqara_g3: hass:Camera-Hub-G3-AB12

More cameras, like Tuya, ONVIF, and possibly others can also be imported by using this method.

Source: ISAPI

This source type support only backchannel audio for Hikvision ISAPI protocol. So it should be used as second source in addition to the RTSP protocol.

streams:
  hikvision1:
    - rtsp://admin:[email protected]:554/Streaming/Channels/101
    - isapi://admin:[email protected]:80/
Source: Roborock

This source type support Roborock vacuums with cameras. Known working models:

  • Roborock S6 MaxV - only video (the vacuum has no microphone)
  • Roborock S7 MaxV - video and two way audio

Source support load Roborock credentials from Home Assistant custom integration. Otherwise, you need to log in to your Roborock account (MiHome account is not supported). Go to: go2rtc WebUI > Add webpage. Copy roborock://... source for your vacuum and paste it to go2rtc.yaml config.

If you have graphic pin for your vacuum - add it as numeric pin (lines: 123, 456, 678) to the end of the roborock-link.

Source: WebRTC

This source type support two connection formats:

  • WebRTC/WHEP - is an unapproved standard for WebRTC video/audio viewers. But it may already be supported in some third-party software. It is supported in go2rtc.
  • go2rtc/WebSocket - This format is only supported in go2rtc. Unlike WHEP it supports asynchronous WebRTC connection and two way audio.
streams:
  webrtc1: webrtc:http://192.168.1.123:1984/api/webrtc?src=dahua1
  webrtc2: webrtc:ws://192.168.1.123:1984/api/ws?src=dahua1
Source: WebTorrent

This source can get a stream from another go2rtc via WebTorrent protocol.

streams:
  webtorrent1: webtorrent:?share=huofssuxaty00izc&pwd=k3l2j9djeg8v8r7e
Incoming sources

By default, go2rtc establishes a connection to the source when any client requests it. Go2rtc drops the connection to the source when it has no clients left.

  • Go2rtc also can accepts incoming sources in RTSP, HTTP and WebRTC/WHIP formats
  • Go2rtc won't stop such a source if it has no clients
  • You can push data only to existing stream (create stream with empty source in config)
  • You can push multiple incoming sources to same stream
  • You can push data to non empty stream, so it will have additional codecs inside

Examples

  • RTSP with any codec
    ffmpeg -re -i BigBuckBunny.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://localhost:8554/camera1
    
  • HTTP-MJPEG with MJPEG codec
    ffmpeg -re -i BigBuckBunny.mp4 -c mjpeg -f mpjpeg http://localhost:1984/api/stream.mjpeg?dst=camera1
    
  • HTTP-FLV with H264, AAC codecs
    ffmpeg -re -i BigBuckBunny.mp4 -c copy -f flv http://localhost:1984/api/stream.flv?dst=camera1
    
  • MPEG-TS with H264 codec
    ffmpeg -re -i BigBuckBunny.mp4 -c copy -f mpegts http://localhost:1984/api/stream.ts?dst=camera1
    
Incoming: Browser

You can turn the browser of any PC or mobile into an IP-camera with support video and two way audio. Or even broadcast your PC screen:

  1. Create empty stream in the go2rtc.yaml
  2. Go to go2rtc WebUI
  3. Open links page for you stream
  4. Select camera+microphone or display+speaker option
  5. Open webrtc local page (your go2rtc should work over HTTPS!) or share link via WebTorrent technology (work over HTTPS by default)
Incoming: WebRTC/WHIP

You can use OBS Studio or any other broadcast software with WHIP protocol support. This standard has not yet been approved. But you can download OBS Studio dev version:

Stream to camera

go2rtc support play audio files (ex. music or TTS) and live streams (ex. radio) on cameras with two way audio support (RTSP/ONVIF cameras, TP-Link Tapo, Hikvision ISAPI, Roborock vacuums, any Browser).

API example:

POST http://localhost:1984/api/streams?dst=camera1&src=ffmpeg:http://example.com/song.mp3#audio=pcma#input=file
  • you can stream: local files, web files, live streams or any format, supported by FFmpeg
  • you should use ffmpeg source for transcoding audio to codec, that your camera supports
  • you can check camera codecs on the go2rtc WebUI info page when the stream is active
  • some cameras supp

Tag summary

Content type

Image

Digest

sha256:96aedd514

Size

101.2 MB

Last updated

about 2 years ago

docker pull skrashevich/go2rtc