Golang(9):Xubuntu 系统,使用Golang,开发直播流媒体服务器livego , 并使用 OBS 推流本地视频到本地服务器,并使用vlc 播放视频。

目录

  • 前言
  • 1,关于Golang 直播 livego
  • 2,使用 OBS
  • 3,总结

前言


相关Golang 全部分类:
https://blog.csdn.net/freewebsys/category_2120333.html

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/104874038

未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys

1,关于Golang 直播 livego


一个非常不错的流媒体服务器:livego

https://github.com/gwuhaolin/livego

然后下载编译:

$ mkdir $GOPATH/src/github.com/gwuhaolin
$ cd $GOPATH/src/github.com/gwuhaolin

$ git clone https://github.com/gwuhaolin/livego.git
正克隆到 'livego'...
remote: Enumerating objects: 440, done.
remote: Total 440 (delta 0), reused 0 (delta 0), pack-reused 440
接收对象中: 100% (440/440), 124.50 KiB | 135.00 KiB/s, 完成.
处理 delta 中: 100% (206/206), 完成.

$ cd livego/
$ ls
av  configure  container  Dockerfile  go.mod  go.sum  LICENSE  main.go  parser  protocol  README.md  utils

$ go mod download
go: finding github.com/davecgh/go-spew v1.1.0
go: finding github.com/stretchr/objx v0.1.0
go: finding github.com/stretchr/testify v1.4.0
go: finding gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15

$ go build main.go 
$ ls
av  configure  container  Dockerfile  go.mod  go.sum  LICENSE  main  main.go  parser  protocol  README.md  utils

$ ./main
2020/03/13 21:48:59 main.go:118: start livego, version master
2020/03/13 21:48:59 liveconfig.go:35: starting load configure file(.livego.json)......
2020/03/13 21:48:59 liveconfig.go:42: loadconfig: 
{
  "server": [
    {
      "appname": "live",
      "liveon": "on",
      "hlson": "on"
    }
  ]
}
2020/03/13 21:48:59 liveconfig.go:49: get config json data:{[{live on on []}]}
2020/03/13 21:48:59 main.go:43: HLS listen On :7002
2020/03/13 21:48:59 main.go:62: hls server enable....
2020/03/13 21:48:59 main.go:70: RTMP Listen On :1935
2020/03/13 21:48:59 main.go:105: HTTP-Operation listen On :8090
2020/03/13 21:48:59 main.go:87: HTTP-FLV listen On :7001

2,使用 OBS


官网:https://obsproject.com/

特别好的工具,也支持LINUX,特别好。

$ sudo apt-get install -y obs-studio

然后在菜单里面就有了。

Golang(9):Xubuntu 系统,使用Golang,开发直播流媒体服务器livego , 并使用 OBS 推流本地视频到本地服务器,并使用vlc 播放视频。_第1张图片
特别注意,要是没有啥修改的时候。推流地址 是:

url地址: rtmp://localhost:1935/live
流名称是: push

然后菜单点击【开始推流】。

然后可以看到日志:

2020/03/13 21:55:48 rtmp.go:123: handleConn: IsPublisher=true
2020/03/13 21:55:48 stream.go:33: HandleReader: info[<key: live/push, URL: rtmp://localhost:1935/live/push, UID: sSG-YrVeR6-lL2DX, Inter: false>]
2020/03/13 21:55:48 rtmp.go:130: new publisher: <key: live/push, URL: rtmp://localhost:1935/live/push, UID: sSG-YrVeR6-lL2DX, Inter: false>
2020/03/13 21:55:48 rtmp.go:134: handleConn:writeType=*hls.Server
2020/03/13 21:55:48 hls.go:62: new hls source
2020/03/13 21:55:48 stream.go:57: HandleWriter: info[<key: live/push, URL: rtmp://localhost:1935/live/push, UID: sSG-YrVeR6-lL2DX, Inter: true>]
2020/03/13 21:55:48 muxer.go:159: flv dvr save stream to:  live/push_1584107748.flv
2020/03/13 21:55:48 source.go:130: [<key: live/push, URL: rtmp://localhost:1935/live/push, UID: sSG-YrVeR6-lL2DX, Inter: true>] hls sender start
2020/03/13 21:55:48 stream.go:311: TransStart:<key: live/push, URL: rtmp://localhost:1935/live/push, UID: sSG-YrVeR6-lL2DX, Inter: false>
2020/03/13 21:55:48 stream.go:167: StartStaticPush: current streamname=push, appname=live
2020/03/13 21:55:48 stream.go:170: StartStaticPush: GetStaticPushList error=no static push url
2020/03/13 21:55:48 muxer.go:167: new flv dvr:  <key: live/push, URL: rtmp://localhost:1935/live/push, UID: HPi3mZlKTGm1txpt, Inter: false>
2020/03/13 21:55:48 stream.go:57: HandleWriter: info[<key: live/push, URL: rtmp://localhost:1935/live/push, UID: HPi3mZlKTGm1txpt, Inter: false>]
2020/03/13 21:56:24 server.go:102: url: /live/push.flv path: live/push paths: [live push]
2020/03/13 21:56:24 stream.go:57: HandleWriter: info[<key: live/push, URL: /live/push.flv, UID: wasvuIrcSLG-1GO1, Inter: true>]
2020/03/13 21:57:41 server.go:102: url: /live/push.flv path: live/push paths: [live push]

然后可以使用VLC 进行播放了:

VLC 的播放菜单里面有地址:

Golang(9):Xubuntu 系统,使用Golang,开发直播流媒体服务器livego , 并使用 OBS 推流本地视频到本地服务器,并使用vlc 播放视频。_第2张图片

然后就可以播放了,配置 OBS 有b站的视频:

https://www.bilibili.com/video/av39313496?

还有 flv.js 播放器:

https://github.com/gwuhaolin/reflv

要是包错误:


推流地址:

rtmp://localhost:1935/live
push

日志:
2020/03/13 21:55:48 stream.go:170: StartStaticPush: GetStaticPushList error=no static push url
2020/03/13 21:55:48 muxer.go:167: new flv dvr:  <key: live/push, URL: rtmp://localhost:1935/live/push, UID: HPi3mZlKTGm1txpt, Inter: false>
2020/03/13 21:55:48 stream.go:57: HandleWriter: info[<key: live/push, URL: rtmp://localhost:1935/live/push, UID: HPi3mZlKTGm1txpt, Inter: false>]


播放地址
http://127.0.0.1:7001/live/push.flv

3,总结


Golang 高性能,非常好。
搭建一个 直播服务器非常简单。当然后续建权也没有研究。就是跑了一个Demo。
后续研究下代码。先记录下。

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/104874038

博主地址是:https://blog.csdn.net/freewebsys

你可能感兴趣的:(golang)