NMS内建支持简单且非常安全的,基于密码和过期时间的鉴权模式。
与阿里云的直播鉴权模式比较类似。
开启方法
打开config.ini
鉴权密码
1 |
auth_key = authkey@2019 |
播放鉴权开关
1 |
auth_play = 1 |
0-关闭,1-打开
推流鉴权开关
1 |
auth_push = 1 |
0-关闭,1-打开
NMS内建支持简单且非常安全的,基于密码和过期时间的鉴权模式。
与阿里云的直播鉴权模式比较类似。
打开config.ini
1 |
auth_key = authkey@2019 |
1 |
auth_play = 1 |
0-关闭,1-打开
1 |
auth_push = 1 |
0-关闭,1-打开
NMS支持在服务端收到流开始播放,结束播放,开始推流,结束推流时回调一个web服务接口。
可作为后台管理程序进行自定义鉴权,统计推流播放信息包括ip,开始结束时间,url参数,使用流量等。
打开config.ini文件,取消notify_url前的注释,填上接收回调的web api地址。
如:
1 |
notify_url = http://192.168.0.8:8008/notify |
我们使用nodejs创建一个简单的web api接口,并打印接收到的信息
继续阅读“NMS v3系列教程之 五、事件通知”程序运行后,可通过浏览器访问 http://server_ip:8000/ 访问nms管理后台
当配置文件项 auth_api 开启并且正确设置了auth_api_user和auth_api_pass,第一次打开管理后台页面时,需要进行登陆。
nms直接运行后,可以看到控制台输出打印
1 2 3 4 5 6 7 8 9 10 11 12 |
2019/12/05 21:54:55 [I] NMS Version:3.1.12 2019/12/05 21:54:55 [I] Copyright:©2019 NodeMedia. 2019/12/05 21:54:55 [I] Website:www.nodemedia.cn 2019/12/05 21:54:55 [I] Author:Chen Mingliang [illuspas@msn.com] 2019/12/05 21:54:55 [I] Build Time:2019.12.03.163435 2019/12/05 21:54:55 [I] Commit Hash:311fd18bf4c1896b94260f4cad290e064951208d 2019/12/05 21:54:55 [D] RLIMIT_NOFILE 10240 2019/12/05 21:54:55 [I] Machine ID:[587dcbb5885f3ca14e87fde14e01c36da31eff15bf37f86df2c0402f0e06be27] 2019/12/05 21:54:55 [I] Free trial, exprition date:2020-06-01 2019/12/05 21:54:55 [I] Node Rtmp Server start on port 1935 2019/12/05 21:54:55 [I] Node Http Server start on port 8000 2019/12/05 21:54:55 [I] Node Https Server start on port 8443 |
可以看到 rtmp服务绑定1935端口,http和https端口分别是8000和8443
1935作为rtmp的默认端口,可以在使用时不填写,比如
1 2 3 4 |
# ffmpeg 推流 ffmpeg -re -i INPUT.mp4 -c copy -f flv rtmp://server_ip/live/stream # ffplay 播放 ffplay tmp://server_ip/live/stream |
8000端口作为http-flv和websocket-flv端口,需要跟上端口号和.flv后缀
1 2 3 4 |
# ffplay 播放 ffplay http://server_ip:8000/live/stream.flv # html5 websocket播放 ws://server_ip:8000/live/stream.flv |
API接口和管理后台复用8000和8443端口,浏览器直接访问web后台
http://server_ip:8000/
https://nodemedia.oss-cn-hangzhou.aliyuncs.com/nms/3.1.15/nms-windows-amd64-20191211.zip
https://nodemedia.oss-cn-hangzhou.aliyuncs.com/nms/3.1.15/nms-linux-amd64-20191211.tar.gz
https://nodemedia.oss-cn-hangzhou.aliyuncs.com/nms/3.1.15/nms-linux-arm64-20191211.tar.gz
https://nodemedia.oss-cn-hangzhou.aliyuncs.com/nms/3.1.15/nms-darwin-amd64-20191211.tar.gz
docker run -it —name nms -p 1935:1935 -p 8000:8000 -p 8443:8443 illuspas/nms
Node Media Server 以下简称nms,最初是以node.js实现的RTMP协议流媒体服务端。
最新v3版使用go语言重写了整个项目,获得了更好的并发性能,也拥有了更强的功能。
上一篇《用Go语言开发的新版NodeMediaServer》说到使用了CGO实现的内置音频实时转码器。开发中遇到一个很严重的问题:无法直接生成跨平台可执行程序了。
首选我们了解到,Go语言是可以在开发平台直接生成多个目标架构和系统的可执行程序。只需要在编译前指定GOOS和GOARCH,便可以直接生成目标文件。
但当使用了CGO,便失去了这种能力。在本机平台以外,需要设置CGO_ENABLED,并且指定CC. linux和macos还好,windows也是需要gcc工具链,这个就需要部署MinGW等很复杂的操作。
在多次尝试后,受到这个项目的启发,编写了一个更简单的xcgo docker image.
之前曾介绍过一款用Node.JS实现的开源RTMP流媒体服务端。目前更新到2.1.3版本,这是个从15年出开始接触Node.js作为研习而建立的项目。说起写完这个项目,对理解nodejs异步架构,rtmp网络协议还是起到了非常重要的作用。
rtmp协议如果用异步解析数据还是比较麻烦的,最早的版本写了个buffer缓冲,再用Generators/yield来转成同步逻辑,简单了许多。接触到async、await后又更新了个版本,代码可读性提高了不少。最后又学习了一个异步状态机的实现,比较满意。
今天接到一个客户的需求,在不改变原有fms服务架构的条件下,对接到Node-Media-Server,提供HLS,RTMP,Http-FLV音频转码服务。
客户以往的架构是Flash在web推流,h.264+Nellymoser编码格式,这个用flash播放是没有问题的
但flash基本上已经被各大浏览器列为默认关闭了,Android,iOS等更是不会支持的。
现在的解决方案,基本上是往HLS,http-flv上靠。HLS提供了最好的兼容性,http-flv提供了最低的延迟性,各有优劣吧。
关键的问题在于,Nellymoser编码并非互联网上广泛支持的格式,就算服务端支持,客户端也基本(有h5客户端支持,后话)上无法实现。
因此,还需要使用ffmpeg进行音频转码。
架构如下:
fms端使用服务端编程,监听 onPublish 和 onUnpublish事件,将参数通过http传参调用。
nms增加api接口收到开始和结束的事件,调起ffmpeg从fms拉流,copy视频,aac编码音频后推到Node-Media-Server。
Node-Media-Server则提供出hls,rtmp,http-flv流。
注:NodePlayer.js 支持web浏览器解码播放Nellymoser,并且兼容各大pc,安卓,iPhone。
需要了解方案详情欢迎与我联系
In other news, GStreamer is now almost buzzword-compliant! The next blog post on our list: blockchains and smart contracts in GStreamer.
Late last year, we at Centricular announced a new implementation of WebRTC in GStreamer. Today we’re happy to announce that after community review, that work has been merged into GStreamer itself! The plugin is called webrtcbin, and the library is, naturally, called gstwebrtc.
The implementation has all the basic features, is transparently compatible with other WebRTC stacks (particularly in browsers), and has been well-tested with both Firefox and Chrome.
Some of the more advanced features such as FEC are already a work in progress, and others will be too—if you want them to be! Hop onto IRC on #gstreamer @ Freenode.net or join the mailing list.
Currently, the easiest way to use webrtcbin is to build GStreamer using either gst-uninstalled(Linux and macOS) or Cerbero (Windows, iOS, Android). If you’re a patient person, you can follow @gstreamer and wait for GStreamer 1.14 to be released which will include Windows, macOS, iOS, and Android binaries.
The API currently lacks documentation, so the best way to learn it is to dive into the source-tree examples. Help on this will be most appreciated! To see how to use GStreamer to do WebRTC with a browser, checkout the bidirectional audio-video demos that I wrote.