mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
优化hls录制
This commit is contained in:
parent
1169f29ca6
commit
a1e5724c70
@ -134,4 +134,8 @@ void HlsMaker::flushLastSegment(bool eof){
|
||||
_last_file_name.clear();
|
||||
}
|
||||
|
||||
bool HlsMaker::isLive() {
|
||||
return _seg_number != 0;
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
@ -87,6 +87,11 @@ protected:
|
||||
* @param eof
|
||||
*/
|
||||
void flushLastSegment(bool eof = false);
|
||||
|
||||
/**
|
||||
* 是否为直播
|
||||
*/
|
||||
bool isLive();
|
||||
private:
|
||||
/**
|
||||
* 生成m3u8文件
|
||||
|
@ -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){
|
||||
|
@ -58,8 +58,6 @@ private:
|
||||
string _path_hls;
|
||||
string _params;
|
||||
int _buf_size;
|
||||
//是否为点播
|
||||
bool _is_vod;
|
||||
};
|
||||
|
||||
}//namespace mediakit
|
||||
|
Loading…
Reference in New Issue
Block a user