Skip to content

Commit d6baef2

Browse files
committed
feature: support HLS fmp4 segment.
1 parent f8319d6 commit d6baef2

11 files changed

+1830
-126
lines changed

trunk/conf/full.conf

+27
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,13 @@ vhost hls.srs.com {
17871787
# default: off
17881788
enabled on;
17891789

1790+
# whether to use fmp4 as container
1791+
# The default value is off, then HLS use ts as container format,
1792+
# if on, HLS use fmp4 as container format.
1793+
# Overwrite by env SRS_VHOST_HLS_HLS_USE_FMP4 for all vhosts.
1794+
# default: off
1795+
hls_use_fmp4 on;
1796+
17901797
# the hls fragment in seconds, the duration of a piece of ts.
17911798
# Overwrite by env SRS_VHOST_HLS_HLS_FRAGMENT for all vhosts.
17921799
# default: 10
@@ -1852,6 +1859,26 @@ vhost hls.srs.com {
18521859
# Overwrite by env SRS_VHOST_HLS_HLS_TS_FILE for all vhosts.
18531860
# default: [app]/[stream]-[seq].ts
18541861
hls_ts_file [app]/[stream]-[seq].ts;
1862+
# the hls fmp4 file name.
1863+
# we supports some variables to generate the filename.
1864+
# [vhost], the vhost of stream.
1865+
# [app], the app of stream.
1866+
# [stream], the stream name of stream.
1867+
# [2006], replace this const to current year.
1868+
# [01], replace this const to current month.
1869+
# [02], replace this const to current date.
1870+
# [15], replace this const to current hour.
1871+
# [04], replace this const to current minute.
1872+
# [05], replace this const to current second.p
1873+
# [999], replace this const to current millisecond.
1874+
# [timestamp],replace this const to current UNIX timestamp in ms.
1875+
# [seq], the sequence number of fmp4.
1876+
# [duration], replace this const to current ts duration.
1877+
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/dvr#custom-path
1878+
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/delivery-hls#hls-config
1879+
# Overwrite by env SRS_VHOST_HLS_HLS_FMP4_FILE for all vhosts.
1880+
# default: [app]/[stream]-[seq].m4s
1881+
hls_fmp4_file [app]/[stream]-[seq].m4s;
18551882
# the hls entry prefix, which is base url of ts url.
18561883
# for example, the prefix is:
18571884
# http://your-server/

trunk/conf/hls.mp4.conf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# the config for srs to delivery hls
2+
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/sample-hls
3+
# @see full.conf for detail config.
4+
5+
listen 1935;
6+
max_connections 1000;
7+
daemon off;
8+
srs_log_tank console;
9+
http_server {
10+
enabled on;
11+
listen 8080;
12+
dir ./objs/nginx/html;
13+
}
14+
vhost __defaultVhost__ {
15+
hls {
16+
enabled on;
17+
hls_use_fmp4 on;
18+
hls_path ./objs/nginx/html;
19+
hls_fragment 10;
20+
hls_window 60;
21+
}
22+
}

trunk/src/app/srs_app_config.cpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ srs_error_t SrsConfig::check_normal_config()
26832683
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
26842684
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
26852685
&& m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_keys" && m != "hls_fragments_per_key" && m != "hls_key_file"
2686-
&& m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly" && m != "hls_ctx" && m != "hls_ts_ctx") {
2686+
&& m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly" && m != "hls_ctx" && m != "hls_ts_ctx" && m != "hls_use_fmp4" && m != "hls_fmp4_file") {
26872687
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.hls.%s of %s", m.c_str(), vhost->arg0().c_str());
26882688
}
26892689

@@ -6936,6 +6936,31 @@ bool SrsConfig::get_hls_enabled(SrsConfDirective* vhost)
69366936
return SRS_CONF_PREFER_FALSE(conf->arg0());
69376937
}
69386938

6939+
bool SrsConfig::get_hls_use_fmp4(std::string vhost)
6940+
{
6941+
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.hls.hls_use_fmp4"); // SRS_VHOST_HLS_HLS_USE_FMP4
6942+
6943+
static bool DEFAULT = false;
6944+
6945+
SrsConfDirective* conf = get_vhost(vhost);
6946+
if (!conf) {
6947+
return DEFAULT;
6948+
}
6949+
6950+
conf = conf->get("hls");
6951+
6952+
if (!conf) {
6953+
return DEFAULT;
6954+
}
6955+
6956+
conf = conf->get("hls_use_fmp4");
6957+
if (!conf || conf->arg0().empty()) {
6958+
return DEFAULT;
6959+
}
6960+
6961+
return SRS_CONF_PREFER_FALSE(conf->arg0());
6962+
}
6963+
69396964
string SrsConfig::get_hls_entry_prefix(string vhost)
69406965
{
69416966
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.hls.hls_entry_prefix"); // SRS_VHOST_HLS_HLS_ENTRY_PREFIX
@@ -7012,6 +7037,25 @@ string SrsConfig::get_hls_ts_file(string vhost)
70127037
return conf->arg0();
70137038
}
70147039

7040+
string SrsConfig::get_hls_fmp4_file(std::string vhost)
7041+
{
7042+
SRS_OVERWRITE_BY_ENV_STRING("srs.vhost.hls.hls_fmp4_file"); // SRS_VHOST_HLS_HLS_FMP4_FILE
7043+
7044+
static string DEFAULT = "[app]/[stream]-[seq].m4s";
7045+
7046+
SrsConfDirective* conf = get_hls(vhost);
7047+
if (!conf) {
7048+
return DEFAULT;
7049+
}
7050+
7051+
conf = conf->get("hls_fmp4_file");
7052+
if (!conf || conf->arg0().empty()) {
7053+
return DEFAULT;
7054+
}
7055+
7056+
return conf->arg0();
7057+
}
7058+
70157059
bool SrsConfig::get_hls_ts_floor(string vhost)
70167060
{
70177061
SRS_OVERWRITE_BY_ENV_BOOL("srs.vhost.hls.hls_ts_floor"); // SRS_VHOST_HLS_HLS_TS_FLOOR

trunk/src/app/srs_app_config.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ class SrsConfig
933933
// Whether HLS is enabled.
934934
virtual bool get_hls_enabled(std::string vhost);
935935
virtual bool get_hls_enabled(SrsConfDirective* vhost);
936+
// Whether HLS use fmp4 container format
937+
virtual bool get_hls_use_fmp4(std::string vhost);
936938
// Get the HLS m3u8 list ts segment entry prefix info.
937939
virtual std::string get_hls_entry_prefix(std::string vhost);
938940
// Get the HLS ts/m3u8 file store path.
@@ -941,6 +943,8 @@ class SrsConfig
941943
virtual std::string get_hls_m3u8_file(std::string vhost);
942944
// Get the HLS ts file path template.
943945
virtual std::string get_hls_ts_file(std::string vhost);
946+
// Get the HLS fmp4 file path template.
947+
virtual std::string get_hls_fmp4_file(std::string vhost);
944948
// Whether enable the floor(timestamp/hls_fragment) for variable timestamp.
945949
virtual bool get_hls_ts_floor(std::string vhost);
946950
// Get the hls fragment time, in srs_utime_t.

trunk/src/app/srs_app_dash.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SrsInitMp4 : public SrsFragment
3838
};
3939

4040
// The FMP4(Fragmented MP4) for DASH streaming.
41+
// TODO: The FMP4(Fragmented MP4) for HLS streaming.
4142
class SrsFragmentedMp4 : public SrsFragment
4243
{
4344
private:

0 commit comments

Comments
 (0)