Commit 800ab3e1 by xiongziliang

优化hls

parent 730db98a
...@@ -64,7 +64,10 @@ HLSMaker::~HLSMaker() { ...@@ -64,7 +64,10 @@ HLSMaker::~HLSMaker() {
bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, int iEnd) { bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, int iEnd) {
char acWriteBuf[1024]; char acWriteBuf[1024];
std::shared_ptr<FILE> pM3u8File(File::createfile_file(m_strM3u8File.data(), "w"),[](FILE *fp){ std::shared_ptr<FILE> pM3u8File(File::createfile_file(m_strM3u8File.data(), "w"),[](FILE *fp){
if(fp){
fflush(fp);
fclose(fp); fclose(fp);
}
}); });
if (!pM3u8File) { if (!pM3u8File) {
WarnL << "Could not open temporary m3u8 index file (" << m_strM3u8File << "), no index file will be created"; WarnL << "Could not open temporary m3u8 index file (" << m_strM3u8File << "), no index file will be created";
...@@ -75,7 +78,7 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i ...@@ -75,7 +78,7 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i
} }
//最少1秒 //最少1秒
int maxSegmentDuration = 1; int maxSegmentDuration = 0;
for (auto dur : m_iDurations) { for (auto dur : m_iDurations) {
dur /=1000; dur /=1000;
if(dur > maxSegmentDuration){ if(dur > maxSegmentDuration){
...@@ -87,15 +90,17 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i ...@@ -87,15 +90,17 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i
sizeof(acWriteBuf), sizeof(acWriteBuf),
"#EXTM3U\n" "#EXTM3U\n"
"#EXT-X-VERSION:3\n" "#EXT-X-VERSION:3\n"
"#EXT-X-ALLOW-CACHE:NO\n"
"#EXT-X-TARGETDURATION:%u\n" "#EXT-X-TARGETDURATION:%u\n"
"#EXT-X-MEDIA-SEQUENCE:%u\n", "#EXT-X-MEDIA-SEQUENCE:%u\n",
maxSegmentDuration, maxSegmentDuration + 1,
iFirstSegment); iFirstSegment);
} else { } else {
snprintf(acWriteBuf, snprintf(acWriteBuf,
sizeof(acWriteBuf), sizeof(acWriteBuf),
"#EXTM3U\n" "#EXTM3U\n"
"#EXT-X-VERSION:3\n" "#EXT-X-VERSION:3\n"
"#EXT-X-ALLOW-CACHE:NO\n"
"#EXT-X-TARGETDURATION:%u\n", "#EXT-X-TARGETDURATION:%u\n",
maxSegmentDuration); maxSegmentDuration);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论