hls直播支持文件根目录设置在http根目录之外

解决hls保存根目录必须和http根目录一致才能播放的问题
This commit is contained in:
xia-chu
2026-03-09 11:36:51 +08:00
parent b8301bd085
commit eef858ffd3
2 changed files with 43 additions and 37 deletions

View File

@@ -25,13 +25,15 @@ namespace mediakit {
string Recorder::getRecordPath(Recorder::type type, const MediaTuple& tuple, const string &customized_path) {
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
switch (type) {
case Recorder::type_hls_fmp4:
case Recorder::type_hls: {
GET_CONFIG(string, hlsPath, Protocol::kHlsSavePath);
string m3u8FilePath;
auto tail = type == Recorder::type_hls ? "/hls.m3u8" : "/hls.fmp4.m3u8";
if (enableVhost) {
m3u8FilePath = tuple.shortUrl() + "/hls.m3u8";
m3u8FilePath = tuple.shortUrl() + tail;
} else {
m3u8FilePath = tuple.app + "/" + tuple.stream + "/hls.m3u8";
m3u8FilePath = tuple.app + "/" + tuple.stream + tail;
}
//Here we use the customized file path.
if (!customized_path.empty()) {
@@ -54,20 +56,6 @@ string Recorder::getRecordPath(Recorder::type type, const MediaTuple& tuple, con
}
return File::absolutePath(mp4FilePath, recordPath);
}
case Recorder::type_hls_fmp4: {
GET_CONFIG(string, hlsPath, Protocol::kHlsSavePath);
string m3u8FilePath;
if (enableVhost) {
m3u8FilePath = tuple.shortUrl() + "/hls.fmp4.m3u8";
} else {
m3u8FilePath = tuple.app + "/" + tuple.stream + "/hls.fmp4.m3u8";
}
// Here we use the customized file path.
if (!customized_path.empty()) {
return File::absolutePath(m3u8FilePath, customized_path);
}
return File::absolutePath(m3u8FilePath, hlsPath);
}
default: return "";
}
}