videoserver

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 21 Imported by: 0

README

GoDoc Sourcegraph Go Report Card GitHub tag

Golang-based video-server for re-streaming RTSP to HLS/MSE

Table of Contents

About

Simple WS/HTTP server for re-streaming video (RTSP) to client in MSE/HLS format.

It is highly inspired by https://github.com/deepch and his projects. So why am I trying to reinvent the wheel? Well, I'm just trying to fit my needs.

Instalation

Binaries

Linux - link

From source
go get github.com/LdDl/video-server
# or just clone it
# git clone https://github.com/LdDl/video-server.git

Go to root folder of downloaded repository, move to cmd/video_server folder:

cd $CLONED_PATH/cmd/video_server
go build -o video_server main.go

Usage

video_server -h
-conf string
    Path to configuration JSON-file (default "conf.json")
-cpuprofile file
    write cpu profile to file
-memprofile file
    write memory profile to file
Start server

Prepare configuration file (example here). Then run binary:

video_server --conf=conf.json
Test Client-Server

For HLS-based player go to hls-subdirectory.

For MSE-based (websockets) player go to mse-subdirectory.

Then follow this set of commands:

npm install
npm run dev

You will se something like this after succesfull fron-end start:

DONE  Compiled successfully in 1783ms                                                                                                                                                                         12:09:30 PM
App running at:
- Local:   http://localhost:8080/ 

Paste link to the browser and check if video loaded successfully.

Dependencies

GIN web-framework - https://github.com/gin-gonic/gin. License is MIT

Media library - http://github.com/deepch/vdk. License is MIT.

UUID generation and parsing - https://github.com/google/uuid. License is BSD 3-Clause

Websockets - https://github.com/gorilla/websocket. License is BSD 2-Clause

m3u8 library - https://github.com/grafov/m3u8. License is BSD 3-Clause

errors wrapping - https://github.com/pkg/errors . License is BSD 2-Clause

License

You can check it here

Developers

Roman - https://github.com/webver

Pavel - https://github.com/Pavel7824

Dimitrii Lopanov - https://github.com/LdDl

Morozka - https://github.com/morozka

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStreamNotFound     = fmt.Errorf("Stream not found for provided ID")
	ErrStreamHasNoVideo   = fmt.Errorf("Stream has no video")
	ErrStreamDisconnected = fmt.Errorf("Disconnected")
)

Functions

func DisableCamera added in v0.3.2

func DisableCamera(app *Application) func(ctx *gin.Context)

DisableCamera turns off stream for specific stream ID

func EnableCamera added in v0.3.2

func EnableCamera(app *Application) func(ctx *gin.Context)

EnableCamera adds new stream if does not exist

func HLSWrapper added in v0.2.0

func HLSWrapper(app *Application) func(ctx *gin.Context)

HLSWrapper returns HLS handler (static files)

func ListWrapper added in v0.2.0

func ListWrapper(app *Application) func(ctx *gin.Context)

ListWrapper returns list of streams

func StatusWrapper added in v0.2.0

func StatusWrapper(app *Application) func(ctx *gin.Context)

StatusWrapper returns statuses for list of streams

func WebSocketWrapper added in v0.2.0

func WebSocketWrapper(app *Application, wsUpgrader *websocket.Upgrader) func(ctx *gin.Context)

WebSocketWrapper returns WS handler

Types

type APIConfiguration added in v0.4.0

type APIConfiguration struct {
	Enabled bool   `json:"-"`
	Host    string `json:"host"`
	Port    int32  `json:"port"`
	Mode    string `json:"-"`
}

APIConfiguration is just copy of configuration.APIConfiguration but with some not exported fields

type Application added in v0.2.0

type Application struct {
	APICfg         APIConfiguration   `json:"api"`
	VideoServerCfg VideoConfiguration `json:"video"`
	Streams        StreamsStorage     `json:"streams"`
	HLS            HLSInfo            `json:"hls"`
	CorsConfig     *cors.Config       `json:"-"`
}

Application is a configuration parameters for application

func NewApplication added in v0.2.0

func NewApplication(cfg *configuration.Configuration) (*Application, error)

NewApplication Prepare configuration for application

func (*Application) StartAPIServer added in v0.3.2

func (app *Application) StartAPIServer()

StartAPIServer starts server with API functionality

func (*Application) StartStream added in v0.3.2

func (app *Application) StartStream(k uuid.UUID)

StartStream starts single video stream

func (*Application) StartStreams added in v0.2.0

func (app *Application) StartStreams()

StartStreams starts all video streams

func (*Application) StartVideoServer added in v0.3.2

func (app *Application) StartVideoServer()

StartVideoServer initializes "video" server and run it (MSE-websockets and HLS-static files)

type EnablePostData added in v0.3.2

type EnablePostData struct {
	GUID        uuid.UUID `json:"guid"`
	URL         string    `json:"url"`
	StreamTypes []string  `json:"stream_types"`
}

EnablePostData is a POST-body for API which enables to turn on/off specific streams

type HLSInfo added in v0.4.0

type HLSInfo struct {
	MsPerSegment int64  `json:"hls_ms_per_segment"`
	Directory    string `json:"-"`
	WindowSize   uint   `json:"hls_window_size"`
	Capacity     uint   `json:"hls_window_capacity"`
}

HLSInfo is an information about HLS parameters for server

type ServerInfo added in v0.2.0

type ServerInfo struct {
	HTTPAddr      string `json:"http_addr"`
	VideoHTTPPort int32  `json:"http_port"`
	APIHTTPPort   int32  `json:"-"`
}

ServerInfo is an information about server

type StreamConfiguration

type StreamConfiguration struct {
	URL                  string               `json:"url"`
	Status               bool                 `json:"status"`
	SupportedStreamTypes []string             `json:"supported_stream_types"`
	Codecs               []av.CodecData       `json:"codecs"`
	Clients              map[uuid.UUID]viewer `json:"-"`
	// contains filtered or unexported fields
}

StreamConfiguration is a configuration parameters for specific stream

func NewStreamConfiguration added in v0.4.0

func NewStreamConfiguration(streamURL string, supportedTypes []string) *StreamConfiguration

NewStreamConfiguration returns default configuration

type StreamInfoShorten added in v0.4.0

type StreamInfoShorten struct {
	StreamID string `json:"stream_id"`
}

type StreamsInfoShortenList added in v0.4.0

type StreamsInfoShortenList struct {
	Data []StreamInfoShorten `json:"data"`
}

type StreamsStorage added in v0.4.0

type StreamsStorage struct {
	sync.Mutex
	Streams map[uuid.UUID]*StreamConfiguration `json:"rtsp_streams"`
}

StreamsStorage Map wrapper for map[uuid.UUID]*StreamConfiguration with mutex for concurrent usage

func NewStreamsStorageDefault added in v0.4.0

func NewStreamsStorageDefault() StreamsStorage

NewStreamsStorageDefault prepares new allocated storage

type VideoConfiguration added in v0.4.0

type VideoConfiguration struct {
	Host string `json:"host"`
	Port int32  `json:"port"`
	Mode string `json:"-"`
}

VideoConfiguration is just copy of configuration.VideoConfiguration but with some not exported fields

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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