转载请注明出处:https://blog.csdn.net/impingo
项目地址:https://github.com/im-pingo/pingos
项目官网:https://pingos.io
owt-server提供了一个官方demo和控制台接口来实现拉流、合流、转推以及录制的功能。关于owt-server的安装过程请参考我之前的文章编译和安装OWT-Server
看如下示例:
room-new.sh
#!/bin/bash
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '
{
"name": "pingos",
"options": {
"mode": "hybrid",
"publishLimit": -1,
"userLimit": 30,
"viewports": [
{
"name": "common",
"mediaMixing": {
"video": {
"maxInput": 15,
"resolution": "hd720p",
"quality_level": "standard",
"bkColor": {"r":1, "g":2, "b":255},
"layout": {
"base": "fluid"
},
"avCoordinated": 1,
"crop": 0
},
"audio": null
}
},
{
"name": "another",
"mediaMixing": {
"video": {
"maxInput": 15,
"resolution": "hd1080p",
"quality_level": "standard",
"bkColor": {"r":1, "g":2, "b":255},
"layout": {
"base": "fluid"
},
"avCoordinated": 1,
"crop": 1
},
"audio": null
}
}
]
}
}
' https://$1:3004/rooms
上面主要参数通过命名基本上就可以推测出它的含义。
这里重点强调一下“viewports”,viewports的作用是允许你创建房间时定义多个合流模板,每个合流模板的名字用“name”指定。在你之后的添加输入流的操作中需要指定使用哪个合流模板。
将上面的脚本保存成room-new.sh
执行脚本,可创建房间。返回的json内容里有该房间的id,注意:后续的所有操作都要带上这个返回的房间id。
./room-new.sh your-owt-ip
#!/bin/bash
ip=$1
roomid=$2
instream=$3
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X POST -d "
{
\"url\": \"$instream\",
\"transport\":{
\"protocol\": \"udp\",
\"bufferSize\": 2048000
},
\"media\": {
\"audio\": \"auto\",
\"video\": \"auto\"
}
}
" https://$ip:3004/rooms/$roomid/streaming-ins
保存脚本,执行拉取你想要合并的流。
刷新输入流的目的是指定输入流应该接入的合流模板(muxer)
#!/bin/bash
ip=$1
roomid=$2
instream=$3
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X PATCH -d '
[{
"op": "add",
"path": "/info/inViews",
"value": "common"
}]
' https://$ip:3004/rooms/$roomid/streams/$instream
保存脚本内容为stream-update.sh,并执行。
#!/bin/bash
ip=$1
roomid=$2
outstream=$3
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X POST -d " \
{
\"roomId\": \"$roomid\",
\"protocol\": \"rtmp\",
\"url\": \"$outstream\",
\"media\": {
\"audio\": {
\"from\": \"$roomid-common\"
},
\"video\": {
\"from\": \"$roomid-common\",
\"parameters\": {
\"keyFrameInterval\": 2
}
}
}
}
" https://$ip:3004/rooms/$roomid/streaming-outs
保存脚本内容,并且执行。
该篇文章中以输出rtmp为例,将合流后的内容通过rtmp协议推流到pingos服务器。合流后的效果如下:
#!/bin/bash
ip=$1
roomid=$2
instream=$3
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X DELETE https://$ip:3004/rooms/$roomid/streaming-ins/$instream
#!/bin/bash
ip=$1
roomid=$2
outstream=$3
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X DELETE https://$ip:3004/rooms/$roomid/streaming-outs/$outstream
#!/bin/bash
ip=$1
roomid=$2
curl -k -H "Accept: application/json" -H "Content-type: application/json" -X DELETE https://$ip:3004/rooms/$roomid