webrtp

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-webrtp

Golang library for streaming RTP packet from RTSP source directly to web in real-time.

Screenshot

WebRTP Dashboard

Usage

Download Binary

Download the latest release binary from GitHub Releases:

# macOS (Apple Silicon)
curl -L -o webrtp https://github.com/connectedtechco/go-webrtp/releases/latest/download/webrtp-darwin-arm64
chmod +x webrtp

# macOS (Intel)
curl -L -o webrtp https://github.com/connectedtechco/go-webrtp/releases/latest/download/webrtp-darwin-amd64
chmod +x webrtp

# Linux
curl -L -o webrtp https://github.com/connectedtechco/go-webrtp/releases/latest/download/webrtp-linux-amd64
chmod +x webrtp
Run Server

Create a config.yml file:

upstreams:
  - name: camera1
    rtspUrl: rtsp://192.168.1.100:554/stream

Run the server:

./webrtp -c config.yml
Command Options
  -c, --config string    Config file path (default: config.yml)
  -i, --interface       Use graphical interface (default: false)
  -p, --port int        HTTP server port (default: 8080)
Access Streams
  • Web UI: http://localhost:8080/
  • Stream by name: ws://localhost:8080/stream/camera1
  • Stream by number: ws://localhost:8080/stream/no/0

Libraries

JavaScript / TypeScript

See client/javascript for the JavaScript client library.

npm install @connectedtechco/webrtp
import { createClient } from '@connectedtechco/webrtp';

const client = createClient('ws://localhost:8080/stream/no/0');
client.render(document.getElementById('canvas'));

client.onInfo((info) => {
    console.log('Info:', info);
});

client.onFrame((frameNo, data, isKey) => {
    console.log(`Frame ${frameNo}: ${data.byteLength} bytes, keyframe: ${isKey}`);
});
Python

See client/python for the Python client library.

cd client/python
uv pip install -e .
from webrtp import WebRtpClient
import cv2

client = WebRtpClient("ws://localhost:8080/stream/no/0")

# Get raw frame data with callback
client.on_raw(lambda frame_no, data, is_key: print(f"Frame: {frame_no}, size: {len(data)}"))

# Get decoded frame with callback
client.on_frame(lambda frame_no, frame: cv2.imshow('video', frame))

client.start()

Development

  1. Generate self-signed certificate for TLS connection

    mkdir -p .local
    openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -keyout .local/x509-key.pem -out .local/x509-cer.pem -days 365 -nodes -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
    
  2. Build styles (run in background)

    sass --watch command/webrtp/index.scss:command/webrtp/index.css
    
  3. Run the server

    go run ./command/webrtp/
    

Documentation

Overview

Package webrtp provides RTSP to WebSocket streaming with fMP4 output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnexbToAvcc

func AnnexbToAvcc(au [][]byte) []byte

AnnexbToAvcc converts Annex-B NAL units to AVCC format.

func BuildFragment

func BuildFragment(seqNr uint32, dts uint64, dur uint32, isIDR bool, avcc []byte) ([]byte, error)

BuildFragment creates an fMP4 media fragment.

func BuildInitH264

func BuildInitH264(sps, pps []byte) ([]byte, error)

BuildInitH264 creates an fMP4 init segment for H264 video.

func BuildInitH265

func BuildInitH265(vps, sps, pps []byte) ([]byte, error)

BuildInitH265 creates an fMP4 init segment for H265 video.

Types

type Config

type Config struct {
	Rtsp            string
	Logger          *log.Logger
	WriteTimeout    time.Duration
	ReadBufferSize  int
	WriteBufferSize int
}

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub

func (*Hub) Broadcast

func (r *Hub) Broadcast(data []byte)

func (*Hub) GetInit

func (r *Hub) GetInit() []byte

func (*Hub) GetStats

func (r *Hub) GetStats(name string) StreamStats

func (*Hub) GetStatus

func (r *Hub) GetStatus() Status

func (*Hub) SetFramerate

func (r *Hub) SetFramerate(framerate float64)

func (*Hub) SetInfo

func (r *Hub) SetInfo(codec string, width, height int, frameRate float64)

func (*Hub) SetInit

func (r *Hub) SetInit(data []byte)

func (*Hub) Subscribe

func (r *Hub) Subscribe() chan []byte

func (*Hub) Unsubscribe

func (r *Hub) Unsubscribe(ch chan []byte)

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

func Init

func Init(cfg *Config) *Instance

func (*Instance) Connect

func (r *Instance) Connect() error

func (*Instance) GetHub

func (r *Instance) GetHub() *Hub

func (*Instance) HandleWebsocket

func (r *Instance) HandleWebsocket(conn *websocket.Conn)

func (*Instance) Handler

func (r *Instance) Handler() fiber.Handler

func (*Instance) InstanceReady

func (r *Instance) InstanceReady() bool

func (*Instance) Start

func (r *Instance) Start(addr string) error

func (*Instance) Stop

func (r *Instance) Stop() error

type Status

type Status struct {
	Streams []*StreamStats `json:"streams"`
}

type StreamStats

type StreamStats struct {
	Name        string        `json:"name"`
	Ready       bool          `json:"ready"`
	Codec       string        `json:"codec"`
	Width       int           `json:"width"`
	Height      int           `json:"height"`
	Framerate   float64       `json:"framerate"`
	FrameNo     uint64        `json:"frameNo"`
	ClientCount int32         `json:"clientCount"`
	BytesRecv   uint64        `json:"bytesRecv"`
	Bitrate     float64       `json:"bitrateKbps"`
	Uptime      time.Duration `json:"uptime"`
}

Directories

Path Synopsis
command
webrtp command
experiment
streamable command
webtransport command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL