nms - A streaming server (push-pull live streams, etc.)

nms - Go language development of high-performance streaming media server

Official Links
nms server document

Download and install

Windows version
https://cdn.nodemedia.cn/nms/3.2.14/nms-windows-amd64-20200224.zip
compressed double-click solution nms.exe
double-click service.bat installed as a service and runs automatically
open the control in the current directory Taiwan output service.bat uninstall stop and uninstall the service

Linux x86_64 version
https://cdn.nodemedia.cn/nms/3.2.14/nms-linux-amd64-20200224.tar.gz
after decompression into the directory, run the console input ./nms
implementation of the program in the current directory sudo ./service.sh install installation services and runs automatically
execute sudo ./service.sh uninstall and stop services to uninstall the program in the current directory

Docker version

    docker run -it —name nms -p 1935:1935 -p 8000:8000 -p 8443:8443 -p 6935:6935/udp illuspas/nms

Linux arm64 version
https://cdn.nodemedia.cn/nms/3.2.14/nms-linux-arm64-20200224.tar.gz
support Huawei Kunpeng cloud ARM64 architecture, KC1 instance running
support Arm linux embedded devices running NMS, can as an internal local area network data acquisition camera push flowmakers public network.
Stable operation, low maintenance costs.
Recommended equipment
NanoPi NEO Plus2

Configuration file (config.ini)

[common]
; 服务绑定地址
bind        = 
; 授权码,程序运行后,将Machine ID值发给客服进行授权
license     = 
; admin_panel 是否开启后台管理面板,需要开启http或https服务
admin_panel = 1
; notify_url 当流创建和结束时以POST方式通知到该url,当通知创建时返回非200状态码,将中断该流
; notify_url  = http://192.168.0.8:8008/notify
; gop_cache 是否开启gop cache, 该功能缓存最近的一段视频gop,使客户端能立刻开始解码秒开。
; 但在服务端有大量推流时需要更多的内存, 根据码率×原视频关键帧间隔×并发量来计算。
gop_cache   = 1

[log]
; trace, debug, info, warn, error
log_level  = debug
; console or real log file path like ./log/nms.log
log_file   = console
; log max day
log_maxday = 7

[av]
; 音频转码开关
; RTMP/FLV协议自动转其它音频编码为AAC
; JT1078协议自动转其它音频编码为G.711A
; WebRTC协议自动转其它音频编码为OPUS
transcode_audio = 1

[auth]
; 鉴权密码,鉴权码生成规则
; 原地址 rtmp://192.168.0.8/live/stream
; 加密算法 先获取有效期时间戳(当前时间+30秒过期)1574318274,md5(/live/stream-1574318274-authkey@2019)
; 最终地址 rtmp://192.168.0.8/live/stream?sign=1574318274-5a1ee174233631793a4091badf4ffec5
auth_key      = authkey@2019
; 播放鉴权开关
auth_play     = 0
; 推流鉴权开关
auth_push     = 0
; API鉴权开关,打开后所有api调用需要设置header['authorization'] = login成功后返回的token
auth_api      = 1
; API鉴权用户名,login时以json格式提交
; {
; "username": "admin",
; "password": "21232f297a57a5a743894a0e4a801fc3"
; }
auth_api_user = admin
; API鉴权密码,login时需要传md5后的值, 默认密码为弱口令,请注意修改
auth_api_pass = admin

[rtmp]
; rtmp协议端口
port       = 1935
; rtmp协议chunk size
chunk_size = 60000

[http]
; http-flv/websocket-flv/hls协议端口
; API接口, AdminPanel复用该端口
port = 8000

[https]
; https-flv/wss-flv/hls 协议端口
port      = 8443
key_file  = key.pem
cert_file = cert.pem

[hls]
; hls_path 切片临时存放路径, 必须填入有效且可写入的路径. 若不设置,则不会生成hls切片
; hls_path = hls
; hls_time 切片时间, 单位秒, 默认2
; 经过这段时间后,将在下一个关键帧上剪切片段. 并不代表肯定会以这个设定值而切片,还要根据关键帧间隔而定.
; 低切片可有效降低hls延迟, 但也需要推流端使用固定的低关键帧间隔编码, 如果不固定关键帧间隔,会造成视频卡顿
hls_time = 2
; hls_list 最大播放条目, 默认3
hls_list = 3

[kmp]
; kmp协议监听, UDP端口
port = 6935

ffmpeg plug flow, the flow pull

NMS v3支持RTMP, HTTP-FLVT推流
① 使用ffmpeg读取本地文件,向nms推送RTMP流
   1.1 INPUT_FILE.mp4 是h264+aac编码
	ffmpeg -re -i INPUT_FILE.mp4 -c copy -f flv rtmp://server_ip/live/stream
   1.2 INPUT_FILE.mp4 是h264+其他音频编码
	ffmpeg -re -i INPUT_FILE.mp4 -c:v copy -c:a aac -f flv rtmp://server_ip/live/stream
   1.3 INPUT_FILE.mp4 是其他音视频编码
	ffmpeg -re -i INPUT_FILE.mp4 -c:v libx264 -tune zerolatency -c:a aac -f flv rtmp://server_ip/live/stream
② 使用ffmpeg读取本地文件,向nms推送HTTP-FLV流
   INPUT_FILE.mp4 是h264+aac编码
	ffmpeg -re -i INPUT_FILE.mp4 -c copy -f flv http://server_ip:8000/live/stream.flv
③ 使用ffmpeg读取RTSP流,向nms推送RTMP流
   INPUT_RTSP 是h264+aac编码
	ffmpeg -re -i rtsp://admin:[email protected]/Streaming/Channels/101 -c copy -f flv rtmp://server_ip/live/stream
④ 使用ffmpeg读取本地H265视频,向nms推送RTMP流
   Adobe官方定义RTMP,FLV是不支持H265的,需要使用打过补丁的ffmpeg.
	linux_x64: https://cdn.nodemedia.cn/ffmpeg/ffmpeg-4.1.4-patch-0.tar.gz
	windows_x64 : https://cdn.nodemedia.cn/ffmpeg/ffmpeg-4.1.4-patch-0.zip


从流媒体服务器播放视频
① 使用ffplay播放 rtmp流
        ffplay rtmp://server_ip/live/stream
② 使用ffplay播放 http-flv流
        ffplay http://server_ip:8000/live/stream.flv
③ 使用ffplay播放 hls流
        ffplay http://server_ip:8000/live/stream.m3u8
④ 使用NodePlayer.js 播放 ws-flv流
        //server_ip:8000/live/stream.flv

Remark

HLS open function

打开config.ini
删除hls_path前的注释
---------------------------------------------------------
[hls]
; hls_path 切片临时存放路径, 必须填入有效且可写入的路径. 若不设置,则不会生成hls切片
hls_path = hls
; hls_time 切片时间, 单位秒, 默认2
; 经过这段时间后,将在下一个关键帧上剪切片段. 并不代表肯定会以这个设定值而切片,还要根据关键帧间 >隔而定.
; 低切片可有效降低hls延迟, 但也需要推流端使用固定的低关键帧间隔编码, 如果不固定关键帧间隔,会造成视频卡顿
hls_time = 2 
; hls_list 最大播放条目, 默认3
hls_list = 3
--------------------------------------------------------

延迟说明
hls_time = 2 
hls_list = 3
代表每2秒切片一个ts,m3u8列表中保持3个ts,这样算下来,延迟是6秒。

极限低延迟
hls_time = 1 
hls_list = 2

播放方式
nms v3版的HLS流同样遵循 /app/stream 资源定位规范,只需要添加.m3u8后缀。
如推流地址:
rtmp://server_ip/live/stream
则hls地址为
http://server_ip:8000/live/stream.m3u8

会话型HLS
nginx-rtmp对HLS的实现模式,只是简单的在推流后只生成m3u8和ts文件,并提供http的静态文件服 > >务。无法进行会话管理,无法统计hls播放量,无法获得播放和结束的事件。
nmsv3的HLS实现,采用了session会话管理,可以定位访问资源的用户id,ip,访问参数,可以使用内置鉴权规则,可以统计播放量,可以统计用户使用的流量,可以获得用户开始播放和结束播放的事件。

H265/HEVC 编码的 HLS流
nms支持H265/HEVC编码的视频输出HLS流,m3u8采用v7,视频采用fMP4切片。

Written in the last

Welcome Message discuss private letter;
articles have informative error, please immediately contact the bloggers, Bo Lord thank you very much;
without going through the permit to use freely reproduced, knowledge has always been widely used to study;
Thank you very much to see here, this article Bo main study notes, if different opinions, please let us know.

Released six original articles · won praise 7 · views 481

Guess you like

Origin blog.csdn.net/Destinyabc/article/details/105365959