增加实用restful接口 (#1183)

This commit is contained in:
rqb500 2021-10-25 15:13:21 +08:00 committed by GitHub
parent 573dc2e67a
commit 5a04575cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 132 additions and 1 deletions

View File

@ -944,6 +944,98 @@
},
"response": []
},
{
"name": "设置录像速度(setRecordSpeed)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{ZLMediaKit_URL}}/index/api/setRecordSpeed?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=obs&speed=2.0",
"host": [
"{{ZLMediaKit_URL}}"
],
"path": [
"index",
"api",
"setRecordSpeed"
],
"query": [
{
"key": "secret",
"value": "{{ZLMediaKit_secret}}",
"description": "api操作密钥(配置文件配置)如果操作ip是127.0.0.1,则不需要此参数"
},
{
"key": "vhost",
"value": "{{defaultVhost}}",
"description": "虚拟主机例如__defaultVhost__"
},
{
"key": "app",
"value": "live",
"description": "应用名,例如 live"
},
{
"key": "stream",
"value": "obs",
"description": "流id例如 obs"
},
{
"key": "speed",
"value": 2.0,
"description": "要设置的录像倍速",
}
]
}
},
"response": []
},
{
"name": "设置录像流播放位置(seekRecordStamp)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{ZLMediaKit_URL}}/index/api/startRecord?secret={{ZLMediaKit_secret}}&vhost={{defaultVhost}}&app=live&stream=obs&stamp=1000",
"host": [
"{{ZLMediaKit_URL}}"
],
"path": [
"index",
"api",
"seekRecordStamp"
],
"query": [
{
"key": "secret",
"value": "{{ZLMediaKit_secret}}",
"description": "api操作密钥(配置文件配置)如果操作ip是127.0.0.1,则不需要此参数"
},
{
"key": "vhost",
"value": "{{defaultVhost}}",
"description": "虚拟主机例如__defaultVhost__"
},
{
"key": "app",
"value": "live",
"description": "应用名,例如 live"
},
{
"key": "stream",
"value": "obs",
"description": "流id例如 obs"
},
{
"key": "stamp",
"value": 1000,
"description": "要设置的录像播放位置",
}
]
}
},
"response": []
},
{
"name": "停止录制(stopRecord)",
"request": {

View File

@ -1038,6 +1038,45 @@ void installWebApi() {
val["msg"] = result ? "success" : "start record failed";
});
//设置录像流播放速度
api_regist("/index/api/setRecordSpeed", [](API_ARGS_MAP) {
CHECK_SECRET();
CHECK_ARGS("schema", "vhost", "app", "stream", "speed");
auto src = MediaSource::find(allArgs["schema"],
allArgs["vhost"],
allArgs["app"],
allArgs["stream"]);
if (src) {
bool flag = src->speed(allArgs["speed"].as<float>());
val["result"] = flag ? 0 : -1;
val["msg"] = flag ? "success" : "set failed";
val["code"] = flag ? API::Success : API::OtherFailed;
} else {
val["result"] = -2;
val["msg"] = "can not find the stream";
val["code"] = API::OtherFailed;
}
});
api_regist("/index/api/seekRecordStamp", [](API_ARGS_MAP) {
CHECK_SECRET();
CHECK_ARGS("schema", "vhost", "app", "stream", "stamp");
auto src = MediaSource::find(allArgs["schema"],
allArgs["vhost"],
allArgs["app"],
allArgs["stream"]);
if (src) {
bool flag = src->seekTo(allArgs["stamp"].as<size_t>());
val["result"] = flag ? 0 : -1;
val["msg"] = flag ? "success" : "seek failed";
val["code"] = flag ? API::Success : API::OtherFailed;
} else {
val["result"] = -2;
val["msg"] = "can not find the stream";
val["code"] = API::OtherFailed;
}
});
// 停止录制hls或MP4
api_regist("/index/api/stopRecord",[](API_ARGS_MAP){
CHECK_SECRET();