新增startRecordTask接口,支持录制事件视频

用户可以录制当前时间前后一定时间内的视频,配置文件gop_cache设置较大时历史视频才能录全
This commit is contained in:
xia-chu
2025-08-02 20:47:49 +08:00
parent b1e1a0f174
commit c9a0025620
4 changed files with 176 additions and 2 deletions

View File

@@ -1776,6 +1776,30 @@ void installWebApi() {
});
});
api_regist("/index/api/startRecordTask",[](API_ARGS_MAP_ASYNC){
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream", "path", "back_ms", "forward_ms");
auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
if (!src) {
throw ApiRetException("can not find the stream", API::NotFound);
}
src->getOwnerPoller()->async([=]() mutable {
std::string err;
std::string path;
try {
path = src->getMuxer()->startRecord(allArgs["path"], allArgs["back_ms"], allArgs["forward_ms"]);
} catch (std::exception &ex) {
err = ex.what();
}
val["code"] = err.empty() ? API::Success : API::OtherFailed;
val["data"]["path"] = path;
val["msg"] = err;
invoker(200, headerOut, val.toStyledString());
});
});
// 设置录像流播放速度 [AUTO-TRANSLATED:a8d82298]
// Set the playback speed of the recording stream
api_regist("/index/api/setRecordSpeed", [](API_ARGS_MAP_ASYNC) {
@@ -1888,11 +1912,13 @@ void installWebApi() {
// http://127.0.0.1/index/api/deleteRecordDirectroy?vhost=__defaultVhost__&app=live&stream=ss&period=2020-01-01
api_regist("/index/api/deleteRecordDirectory", [](API_ARGS_MAP) {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream", "period");
CHECK_ARGS("vhost", "app", "stream");
auto tuple = MediaTuple{allArgs["vhost"], allArgs["app"], allArgs["stream"], ""};
auto record_path = Recorder::getRecordPath(Recorder::type_mp4, tuple, allArgs["customized_path"]);
auto period = allArgs["period"];
record_path = record_path + period + "/";
if (!period.empty()) {
record_path = record_path + period + "/";
}
bool recording = false;
auto name = allArgs["name"];