---
# System prepended metadata

title: IP Camera Stream Transcoder
tags: [IP Camera]

---

---
title: IP Camera Stream Transcoder
tags: IP Camera
---

## RTSP To WebRTC

### RTSPtoWebRTC
1. [install golang binary](https://go.dev/doc/install)
2. clone RTSPtoWebRTC `git clone https://github.com/deepch/RTSPtoWebRTC`
3. cd RTSPtoWebRTC/
4. modify config.json
5. Test Run `GO111MODULE=on go run *.go`
6. open web browser `http://host:8083`

### GO2RTC
* [download binary](https://github.com/AlexxIT/go2rtc/releases/)
* Docker
	1. create go2rtc.yaml
		```
        api:
          listen: ":1984"
          base_path: ""
          static_dir: ""
          origin: ""

        ffmpeg:
          bin: "ffmpeg"
          global: "-hide_banner"
          file: "-re -stream_loop -1 -i {input}"
          http: "-fflags nobuffer -flags low_delay -i {input}"
          rtsp: "-fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"
          output: "-user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}"
		  # ... different presets for codecs

        hass:
          config: ""

        log:
          format: ""
          level: "info"

        ngrok:
          command: ""

        rtsp:
          listen: ":8554"
          username: ""
          password: ""

        srtp:
          listen: ":8443"

        streams: 
          camera: "rtsp://admin:admin@192.168.1.139:8554/live",
          video: "rtsp://${host}:${port}/${prefix}",
		  ...
        webrtc:
          listen: ":8555"
          candidates: []
          ice_servers:
            - urls: [ "stun:stun.l.google.com:19302" ]
              username: ""
              credential: ""
		```
	2. create docker-compose.yml
		```
		version: '3.0'
		services:
          go2rtc:
            image: alexxit/go2rtc
		    network_mode: host       # important for WebRTC, HomeKit, UDP cameras
            privileged: true         # only for FFmpeg hardware transcoding
            restart: unless-stopped  # autorestart on fail or config change from WebUI
            environment:
              - TZ=Asia/Taipei       # timezone in logs
            volumes:
              - "./:/config"         # folder for go2rtc.yaml file (edit from WebUI)
		```


## Mock RTSP Stream

### Host By Android Studio Emulator With RTSP Security Server

terminal 1
1. `emulator -avd [device_name]`
2. emulator power on
3. wait till Boot completed
4. open RTSP Security Server App

terminal 2
1. `telnet localhost [console_port]`
2. `auth [auth_token]`
3. `redir add tcp:1935:1935`
4. `quit`
5. `netsh interface portproxy add v4tov4 listenaddress=[host_ip] listenport=1935 connectaddress=127.0.0.1 connectport=1935`