diff --git a/src/Record/HlsMaker.cpp b/src/Record/HlsMaker.cpp index 8c5b2994..039254b9 100644 --- a/src/Record/HlsMaker.cpp +++ b/src/Record/HlsMaker.cpp @@ -134,4 +134,8 @@ void HlsMaker::flushLastSegment(bool eof){ _last_file_name.clear(); } +bool HlsMaker::isLive() { + return _seg_number != 0; +} + }//namespace mediakit \ No newline at end of file diff --git a/src/Record/HlsMaker.h b/src/Record/HlsMaker.h index 49635a60..cb7f6b23 100644 --- a/src/Record/HlsMaker.h +++ b/src/Record/HlsMaker.h @@ -87,6 +87,11 @@ protected: * @param eof */ void flushLastSegment(bool eof = false); + + /** + * 是否为直播 + */ + bool isLive(); private: /** * 生成m3u8文件 diff --git a/src/Record/HlsMakerImp.cpp b/src/Record/HlsMakerImp.cpp index 88cd724f..cfb76e17 100644 --- a/src/Record/HlsMakerImp.cpp +++ b/src/Record/HlsMakerImp.cpp @@ -40,7 +40,6 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file, _path_hls = m3u8_file; _params = params; _buf_size = bufSize; - _is_vod = seg_number == 0; _file_buf.reset(new char[bufSize],[](char *ptr){ delete[] ptr; }); @@ -49,7 +48,7 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file, HlsMakerImp::~HlsMakerImp() { //录制完了 flushLastSegment(true); - if(!_is_vod){ + if(isLive()){ //hls直播才删除文件 File::delete_file(_path_prefix.data()); } @@ -62,7 +61,9 @@ string HlsMakerImp::onOpenSegment(int index) { auto strTime = getTimeStr("%H-%M-%S"); segment_name = StrPrinter << strDate + "/" + strTime << "_" << index << ".ts"; segment_path = _path_prefix + "/" + segment_name; - _segment_file_paths.emplace(index,segment_path); + if(isLive()){ + _segment_file_paths.emplace(index,segment_path); + } } _file = makeFile(segment_path, true); if(!_file){ diff --git a/src/Record/HlsMakerImp.h b/src/Record/HlsMakerImp.h index ece0213a..c9683510 100644 --- a/src/Record/HlsMakerImp.h +++ b/src/Record/HlsMakerImp.h @@ -58,8 +58,6 @@ private: string _path_hls; string _params; int _buf_size; - //是否为点播 - bool _is_vod; }; }//namespace mediakit