mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-28 21:14:03 +08:00
支持配置 fmp4 HLS 切片文件扩展名 (.mp4/.m4s) (#4746)
## 背景 / 问题 fmp4 模式下,HLS 切片文件名被硬编码为 `.mp4`(见 `HlsMakerImp::onOpenSegment`),无法改用 fmp4 媒体段更规范、更常见的 `.m4s` 扩展名(`init` 段用 `init.mp4`、媒体段用 `.m4s` 是 CMAF/DASH 的通行约定)。 ## 改动 - 新增配置项 `hls.fmp4SegExt`,默认 `.mp4`,**完全向后兼容**;用户可设为 `.m4s`。 - `init` 段仍固定为 `init.mp4`,mpegts 切片仍为 `.ts`,相关行为不变。 - 切片文件名同时用作 m3u8 中的分片 URI,因此扩展名变更后 playlist 自动保持一致,无需额外同步。 - 在 HTTP MIME 表中注册 `.m4s` -> `video/mp4`;否则会以 `text/plain` 返回,导致 Safari 等播放器无法播放 HLS-fmp4。 - 配置值不带前导点(如 `m4s`)时自动规范化为 `.m4s`。 ## 涉及文件 `src/Common/config.h`、`src/Common/config.cpp`、`src/Record/HlsRecorder.h`、`src/Record/HlsMakerImp.h`、`src/Record/HlsMakerImp.cpp`、`src/Http/HttpConst.cpp`、`conf/config.ini` ## 测试 - **默认(未配置)**:切片仍为 `*.mp4`,`init` 为 `init.mp4`,行为与改动前一致(回归正常)。 - **`hls.fmp4SegExt=.m4s`**:切片文件为 `*_N.m4s`,m3u8 中 `#EXTINF` 的 URI 指向 `.m4s`,`#EXT-X-MAP` 仍为 `init.mp4`;HTTP 拉取切片返回 `Content-Type: video/mp4`;hls.js 与 Safari 播放正常。 - **`hls.fmp4SegExt=m4s`(无前导点)**:自动规范化,仍生成 `*.m4s`。 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -355,6 +355,7 @@ const string kFileBufSize = HLS_FIELD "fileBufSize";
|
||||
const string kBroadcastRecordTs = HLS_FIELD "broadcastRecordTs";
|
||||
const string kDeleteDelaySec = HLS_FIELD "deleteDelaySec";
|
||||
const string kFastRegister = HLS_FIELD "fastRegister";
|
||||
const string kFmp4SegExt = HLS_FIELD "fmp4SegExt";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kSegmentDuration] = 2;
|
||||
@@ -366,6 +367,7 @@ static onceToken token([]() {
|
||||
mINI::Instance()[kBroadcastRecordTs] = false;
|
||||
mINI::Instance()[kDeleteDelaySec] = 10;
|
||||
mINI::Instance()[kFastRegister] = false;
|
||||
mINI::Instance()[kFmp4SegExt] = ".mp4";
|
||||
});
|
||||
} // namespace Hls
|
||||
|
||||
|
||||
@@ -531,6 +531,9 @@ extern const std::string kDeleteDelaySec;
|
||||
// 如果设置为1,则第一个切片长度强制设置为1个GOP [AUTO-TRANSLATED:fbbb651d]
|
||||
// If set to 1, the length of the first slice is forced to be 1 GOP
|
||||
extern const std::string kFastRegister;
|
||||
// fmp4 HLS切片文件的扩展名(例如 .mp4 或 .m4s);mpegts切片始终为.ts
|
||||
// File extension for fMP4 HLS segment files (e.g. .mp4 or .m4s); mpegts segments are always .ts
|
||||
extern const std::string kFmp4SegExt;
|
||||
} // namespace Hls
|
||||
|
||||
// //////////Rtp代理相关配置/////////// [AUTO-TRANSLATED:7b285587]
|
||||
|
||||
Reference in New Issue
Block a user