live video streaming server in golang

中文

Test Release

Simple and efficient live broadcast server:

  • Very simple to install and use;
  • Pure Golang, high performance, and cross-platform;
  • Supports commonly used transmission protocols, file formats, and encoding formats;

Supported transport protocols

  • RTMP
  • AMF
  • HLS
  • HTTP-FLV

Supported container formats

  • FLV
  • TS

Supported encoding formats

  • H264
  • AAC
  • MP3

Installation

After directly downloading the compiled binary file, execute it on the command line.

Boot from Docker

Run docker run -p 1935:1935 -p 7001:7001 -p 7002:7002 -p 8090:8090 -d gwuhaolin/livego to start

Compile from source

  1. Download the source code git clone https://github.com/gwuhaolin/livego.git
  2. Go to the livego directory and execute go build or make build

Use

  1. Start the service: execute the livego binary file or make run to start the livego service;
  2. Get a channelkey(used for push the video stream) from http://localhost:8090/control/get?room=movie and copy data like your channelkey.
  3. Upstream push: Push the video stream to rtmp://localhost:1935/{appname}/{channelkey} through the RTMP protocol(default appname is live), for example, use ffmpeg -re -i demo.flv -c copy -f flv rtmp://localhost:1935/{appname}/{channelkey} push(download demo flv);
  4. Downstream playback: The following three playback protocols are supported, and the playback address is as follows:
    • RTMP:rtmp://localhost:1935/{appname}/movie
    • FLV:http://127.0.0.1:7001/{appname}/movie.flv
    • HLS:http://127.0.0.1:7002/{appname}/movie.m3u8

all options:

./livego  -h
Usage of ./livego:
      --api_addr string       HTTP manage interface server listen address (default ":8090")
      --config_file string    configure filename (default "livego.yaml")
      --flv_dir string        output flv file at flvDir/APP/KEY_TIME.flv (default "tmp")
      --gop_num int           gop num (default 1)
      --hls_addr string       HLS server listen address (default ":7002")
      --hls_keep_after_end    Maintains the HLS after the stream ends
      --httpflv_addr string   HTTP-FLV server listen address (default ":7001")
      --level string          Log level (default "info")
      --read_timeout int      read time out (default 10)
      --rtmp_addr string      RTMP server listen address

Use with flv.js

Interested in Golang? Please see Golang Chinese Learning Materials Summary

Owner
浩麟
发简历到我邮箱可内推蚂蚁集团,杭州成都招前端Java
浩麟
Comments
  •  ReadFile .livego.json error:open .livego.json: no such file or directory

    ReadFile .livego.json error:open .livego.json: no such file or directory

    v:0.0.5

    newtest docker run -p 1935:1935 -p 7001:7001 -p 7002:7002 --name livego gwuhaolin/livego 2019/11/04 08:56:28 main.go:118: start livego, version master 2019/11/04 08:56:28 liveconfig.go:35: starting load configure file(.livego.json)...... 2019/11/04 08:56:28 liveconfig.go:38: ReadFile .livego.json error:open .livego.json: no such file or directory

  • 关于性能问题,求助

    关于性能问题,求助

    你好,首先多谢贡献这么好的rtmp server开源。 近期我用SRS_bench对livego做性能测试,测试的设备是阿里16核的服务器。 并发publish 300路rtmp流到livego, CPU占用率比较高。 其中一个原因是内部的报文传递,都直接用的内存copy,而不是应用,导致cpu比较高。 我对大部分的接口进行了修改: type WriteCloser interface { Closer Alive CalcTime Write(Packet) error------>Write(*Packet) error }

    type VirWriter struct { Uid string closed bool av.RWBaser conn StreamReadWriteCloser packetQueue chan av.Packet------>packetQueue chan *av.Packet } 等等,就不贴所有代码了,主要就是用引用传递,而不是每次都做copy。 修改后cpu占用率降下来不少。

    但是目前在300路rtmp publish并发的情况下,CPU占用率还是比较高,50%左右。 定位了一下,主要cpu消耗较多的是下面这个部分: func (s *Stream) TransStart() { ....... for { ...... err := s.r.Read(&p) ...... //Start: 从这里开始的gop cache的处理,cpu消耗非常大!,如果注释掉这部分,性能和SRS rtmp服务器性能差不多 s.cache.Write(p)

    	for item := range s.ws.IterBuffered() {
    		v := item.Val.(*PackWriterCloser)
    		if !v.init {
    			if err = s.cache.Send(v.w); err != nil {
    				log.Printf("[%s] send cache packet error: %v, remove", v.w.Info(), err)
    				s.ws.Remove(item.Key)
    				continue
    			}
    			v.init = true
    		} else {
    			new_packet := p
    			if err = v.w.Write(&new_packet); err != nil {
    				log.Printf("[%s] write packet error: %v, remove", v.w.Info(), err)
    				s.ws.Remove(item.Key)
    			}
    		}
                        //End: 到这里结束
    	}
    

    希望能帮助看看gop cache这部分怎么优化,如果方便,是否能qq交流。这是我的邮箱: [email protected]

  • 新增功能和修改异常崩溃bug

    新增功能和修改异常崩溃bug

    1,配置文件功能 配置application_name, streamname 2,动态push,pull功能 根据http命令来做push和pull 3,静态push功能 通过配置文件,静态push流到上游rtmp服务器; 我整理一下吧,然后再上传。 4,解决大量并发play结束后的崩溃问题 5,解决去使能hls的异常问题

  • 关于livego直播时不断写文件,很容易写爆磁盘的问题,提供一个解决方案

    关于livego直播时不断写文件,很容易写爆磁盘的问题,提供一个解决方案

    在文件livego\container\flv\muxer.go的函数GetWriter中

    	if err != nil {
    		log.Error("open file error: ", err)
    		return nil
    	}
    

    它打开了文件写操作,并且没有关闭。因此会一直写文件。在open后添加defer关闭,生成的文件就只有1k,并且可随时删除,也不影响直播效果,完全不占用磁盘空间

    	w, err := os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0755)
    	defer w.Close()
    	if err != nil {
    		log.Error("open file error: ", err)
    		return nil
    	}
    
  • Module name

    Module name

    Guys, why does your module have a relative name? Why isn't it github.com/gwuhaolin/livego?

    And why are imports on livego made relative?

    This prevents me from using livego as a library. I can make a pool request if it's OK for you

  • 关于音频SpecialCache

    关于音频SpecialCache

    在HLS中,写AAC音频,会修改SpecialCache中的数据,造成后续的播放全部错误,

    func (d *Demuxer) Demux(p *av.Packet) error {
    	var tag Tag
    	n, err := tag.ParseMediaTagHeader(p.Data, p.IsVideo)
    	if err != nil {
    		return err
    	}
    	if tag.CodecID() == av.VIDEO_H264 &&
    		p.Data[0] == 0x17 && p.Data[1] == 0x02 {
    		return ErrAvcEndSEQ
    	}
    	//此处有可能影响缓冲
    	p.Header = &tag
    	p.Data = p.Data[n:]
    
    	return nil
    }
    

    修改位置

    func (specialCache *SpecialCache) Send(w av.WriteCloser) error {
    	if !specialCache.full {
    		return nil
    	}
    	//TODO zhangzj 进行一次赋值,防止被缓冲数据修改
    	packet := *specialCache.p
    	return w.Write(&packet)
    }
    
  • handleConn HandshakeServer err: rtmp: handshake version=80 invalid

    handleConn HandshakeServer err: rtmp: handshake version=80 invalid

    Hi! Run docker run -p 1935:1935 -p 7001:7001 -p 7002:7002 -p 8090:8090 -d gwuhaolin/livego and have error: ERRO[2020-09-04T16:31:23+03:00] handleConn HandshakeServer err: rtmp: handshake version=80 invalid

  • 多次运行中key不变

    多次运行中key不变

    在livego中,对channel生成key的时候使用的是golang的rand包。在golang中rand包生成的是伪随机数,每次运行的seed是不变的。所以虽然在每次运行中各个channel的key不会重复,但是对于多次运行中生成的key是不变的。比如说,第一次运行的时候,第一次生成的key是key1,第二次生成的key是key2,那在第二次运行程序的时候,第一次生成的key肯定也是key1,第二次生成的key肯定也是key2。我们可以在uid的包里面添加一个设置rand的seed的init函数来解决这个问题:

    func init() {
    	// rand.Intn is pseudo-random, set seed to make it vary
    	rand.Seed(time.Now().UnixNano())
    }
    
  • panic: runtime error: invalid memory address or nil pointer dereference

    panic: runtime error: invalid memory address or nil pointer dereference

    运行一段时间,就崩了。。。

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5375b6]
    
    goroutine 449 [running]:
    bufio.(*Writer).Flush(0xc0001fbb40)
    	/usr/local/go/src/bufio/bufio.go:628 +0x56
    bufio.(*Writer).Write(0xc0001fbb40, {0xc0006221a3?, 0x436dd2?, 0xc000214110?})
    	/usr/local/go/src/bufio/bufio.go:672 +0xd8
    net/http.(*response).write(0xc0000ba0e0, 0xbd, {0xc0006221a3, 0xbd, 0x56e5d}, {0x0, 0x0})
    	/usr/local/go/src/net/http/server.go:1615 +0x21e
    net/http.(*response).Write(0xc00023e010?, {0xc0006221a3?, 0x7ce8f?, 0xc00003ef03?})
    	/usr/local/go/src/net/http/server.go:1573 +0x30
    github.com/gwuhaolin/livego/protocol/httpflv.(*FLVWriter).SendPacket(0xc00023e000)
    	/mnt/c/Users/cosx/dev/livego/protocol/httpflv/writer.go:151 +0x1d3
    github.com/gwuhaolin/livego/protocol/httpflv.NewFLVWriter.func1()
    	/mnt/c/Users/cosx/dev/livego/protocol/httpflv/writer.go:55 +0x26
    created by github.com/gwuhaolin/livego/protocol/httpflv.NewFLVWriter
    	/mnt/c/Users/cosx/dev/livego/protocol/httpflv/writer.go:54 +0x42a
    
  • Add a new feature to handle authentication using query path.

    Add a new feature to handle authentication using query path.

    with this new feature we can handle who can have access to the stream, so we can share unique credentials for each user that can access the content of the rtmp stream. also we can control (by ip) to force only one client by shared credential.

  • Bug: 房间号既可以是key, key也可以是房间号

    Bug: 房间号既可以是key, key也可以是房间号

    例如: 房间号aa 串流密钥 rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk

    正常使用 推流 rtmp://localhost:1935/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk 拉流 http://localhost:7001/live/aa.flv

    但发现下面做法也能推拉流成功. 这明显是不符合逻辑. 推流 rtmp://localhost:1935/live/aa 拉流 http://localhost:7001/live/rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk.flv

    解决方法: 建议房间号和串流的 缓存键增加前缀 用以区分, 例如: room:aa key:rfBd56ti2SMtYvSgD5xAV0YU99zampta7Z7S575KLkIZ9PYk

live streaming server in golang
live streaming server in golang

中文 Simple and efficient live broadcast server: Very simple to install and use; Pure Golang, high performance, and cross-platform; Supports commonly us

Nov 10, 2022
Personal video streaming server.

tube This is a Golang project to build a self hosted "tube"-style video player for watching your own video collection over HTTP or hosting your own ch

Jan 5, 2023
Parse and generate m3u8 playlists for Apple HTTP Live Streaming (HLS) in Golang (ported from gem https://github.com/sethdeckard/m3u8)

go-m3u8 Golang package for m3u8 (ported m3u8 gem https://github.com/sethdeckard/m3u8) go-m3u8 provides easy generation and parsing of m3u8 playlists d

Nov 19, 2022
A live streaming tool more suitable for non-graphical servers

KPlayer KPlayer可以帮助你快速的在服务器上进行视频资源的循环直播推流。

Jan 2, 2023
Go-video-preview-ffmpeg-wrapper - A simple helper wrapper to generate small webm video previews using ffmpeg, useful for web previews.

Go-video-preview-ffmpeg-wrapper A simple helper wrapper to generate small webm video previews using ffmpeg, useful for web previews. Getting Started u

Jan 5, 2022
🔥 Golang live stream lib/client/server. support RTMP/RTSP/HLS/HTTP[S]-FLV/HTTP-TS, H264/H265/AAC, relay, cluster, record, HTTP API/Notify, GOP cache. 官方文档见 https://pengrl.com/lal
🔥 Golang live stream lib/client/server. support RTMP/RTSP/HLS/HTTP[S]-FLV/HTTP-TS, H264/H265/AAC, relay, cluster, record, HTTP API/Notify, GOP cache. 官方文档见 https://pengrl.com/lal

lal是一个开源GoLang直播流媒体网络传输项目,包含三个主要组成部分: lalserver:流媒体转发服务器。类似于nginx-rtmp-module等应用,但支持更多的协议,提供更丰富的功能。lalserver简介 demo:一些小应用,比如推、拉流客户端,压测工具,流分析工具,调度示例程序等

Jan 1, 2023
Video converter with golang

Requirements Debian-like system (ubuntu, mint, etc...) with apt package manager Golang >1.15 Command tool make (use sudo apt install make -y to instal

Sep 10, 2022
golang function that download a video from youtube, and convert it to a mp3 file using ffmpeg

echedwnmp3 echedwnmp3 is a function that download a video from youtube, and convert it to a mp3 file using ffmpeg example package main import(echedwn

Dec 7, 2021
lmmp3 is a little golang library that download a video from youtube, and convert it to a mp3 file using ffmpeg

lmmp3 lmmp3 is a function that download a video from youtube, and convert it to a mp3 file using ffmpeg You need to have installed ffmpeg in your syst

Aug 12, 2022
📽 MovieGo - Video Editing in Golang

?? MovieGo - Video Editing in Golang MovieGo is a Golang library for video editing. The library is designed for fast processing of routine tasks relat

Dec 26, 2022
Live on-demand transcoding in go using ffmpeg. Also with NVIDIA GPU hardware acceleration.

Go live HTTP on-demand transcoding Transcoding is expensive and resource consuming operation on CPU and GPU. For big companies with thousands of custo

Dec 16, 2022
Short video direct link acquisition 短视频直连获取工具
Short video direct link acquisition 短视频直连获取工具

Glink 短视频去水印一键解析应用 Short video direct link acquisition 短视频直连获取工具 Glink是一款基于go语言开发的短视频解析应用,前端使用vue+argon主题,后端使用go-fiber框架,支持web在线模式、客户端模式。

Dec 7, 2022
Quik.do is a video conferencing tool.
Quik.do is a video conferencing tool.

Quik.do is a video conferencing tool.

Jan 3, 2023
LiveKit - Open source, distributed video/audio rooms over WebRTC

LiveKit is an open source project that provides scalable, multi-user conferencing over WebRTC. It's designed to give you everything you need to build real time video/audio capabilities in your applications.

Jan 9, 2023
Go4vl is Go library for working with the Video for Linux API (V4L2) natively, without any C bindings.

go4vl A Go library for working with the Video for Linux user API (V4L2). Gov4l hides all the complexities of working with V4L2 and exposes idiomatic G

Dec 23, 2022
A simple library to extract video and audio frames from media containers (based on libav).
A simple library to extract video and audio frames from media containers (based on libav).

Reisen A simple library to extract video and audio frames from media containers (based on libav, i.e. ffmpeg). Dependencies The library requires libav

Jan 2, 2023
Stream video from ffmpeg to webrtc

ffmpeg-to-webrtc demonstrates how to send video from ffmpeg to your browser using pion.

Dec 28, 2022
Project to get Youtube video descriptions and search those videos as required

FamPayProject Project to get Youtube video descriptions and search those videos as required Prerequisities Postgres DB for persisting data Youtube Dat

Nov 5, 2021
Synthetic media is a realistic transformation of audio and video using artificial intelligence.

Synthetic media is a realistic transformation of audio and video using artificial intelligence.

Nov 20, 2021