mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
修复某些流转换hls后花屏的问题
This commit is contained in:
parent
06784d86be
commit
e7727e7e9b
@ -67,38 +67,28 @@ void TsMuxer::inputFrame(const Frame::Ptr &frame) {
|
|||||||
switch (frame->getCodecId()){
|
switch (frame->getCodecId()){
|
||||||
case CodecH265:
|
case CodecH265:
|
||||||
case CodecH264: {
|
case CodecH264: {
|
||||||
|
//这里的代码逻辑是让SPS、PPS、IDR这些时间戳相同的帧打包到一起当做一个帧处理,
|
||||||
Buffer::Ptr merged_frame ;
|
if (!_frameCached.empty() && _frameCached.back()->dts() != frame->dts()) {
|
||||||
if(frame->configFrame()){
|
Frame::Ptr back = _frameCached.back();
|
||||||
//配置帧,缓存后直接返回,以便下次输入关键帧时使用
|
Buffer::Ptr merged_frame = back;
|
||||||
_config_frame_cache.append("\x00\x00\x00\x01",4);
|
if(_frameCached.size() != 1){
|
||||||
_config_frame_cache.append(frame->data() + frame->prefixSize(),frame->size() - frame->prefixSize());
|
string merged;
|
||||||
break;
|
_frameCached.for_each([&](const Frame::Ptr &frame){
|
||||||
}
|
if(frame->prefixSize()){
|
||||||
|
merged.append(frame->data(),frame->size());
|
||||||
if(frame->keyFrame()){
|
|
||||||
//关键帧
|
|
||||||
if(!_config_frame_cache.empty()){
|
|
||||||
//有配置帧,那么配置帧合并关键帧后输入ts打包
|
|
||||||
_config_frame_cache.append("\x00\x00\x00\x01",4);
|
|
||||||
_config_frame_cache.append(frame->data() + frame->prefixSize(),frame->size() - frame->prefixSize());
|
|
||||||
merged_frame = std::make_shared<BufferString>(std::move(_config_frame_cache));
|
|
||||||
_config_frame_cache.clear();
|
|
||||||
} else{
|
} else{
|
||||||
//这是非第一个的关键帧(h265有多种关键帧)
|
merged.append("\x00\x00\x00\x01",4);
|
||||||
merged_frame = frame;
|
merged.append(frame->data(),frame->size());
|
||||||
}
|
}
|
||||||
}else{
|
});
|
||||||
//这里是普通帧,例如B/P,
|
merged_frame = std::make_shared<BufferString>(std::move(merged));
|
||||||
merged_frame = frame;
|
|
||||||
//sps、pps这些配置帧清空掉
|
|
||||||
_config_frame_cache.clear();
|
|
||||||
}
|
}
|
||||||
|
track_info.stamp.revise(back->dts(),back->pts(),dts_out,pts_out);
|
||||||
//输入到ts文件
|
|
||||||
track_info.stamp.revise(frame->dts(),frame->pts(),dts_out,pts_out);
|
|
||||||
_timestamp = dts_out;
|
_timestamp = dts_out;
|
||||||
mpeg_ts_write(_context, track_info.track_id, frame->keyFrame() ? 0x0001 : 0, pts_out * 90LL, dts_out * 90LL, merged_frame->data(), merged_frame->size());
|
mpeg_ts_write(_context, track_info.track_id, back->keyFrame() ? 0x0001 : 0, pts_out * 90LL, dts_out * 90LL, merged_frame->data(), merged_frame->size());
|
||||||
|
_frameCached.clear();
|
||||||
|
}
|
||||||
|
_frameCached.emplace_back(Frame::getCacheAbleFrame(frame));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
|
@ -42,8 +42,8 @@ class TsMuxer : public MediaSink {
|
|||||||
public:
|
public:
|
||||||
TsMuxer();
|
TsMuxer();
|
||||||
virtual ~TsMuxer();
|
virtual ~TsMuxer();
|
||||||
void addTrack(const Track::Ptr &track) ;
|
void addTrack(const Track::Ptr &track) override;
|
||||||
void inputFrame(const Frame::Ptr &frame) ;
|
void inputFrame(const Frame::Ptr &frame) override;
|
||||||
protected:
|
protected:
|
||||||
virtual void onTs(const void *packet, int bytes,uint32_t timestamp,int flags) = 0;
|
virtual void onTs(const void *packet, int bytes,uint32_t timestamp,int flags) = 0;
|
||||||
void resetTracks();
|
void resetTracks();
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
Stamp stamp;
|
Stamp stamp;
|
||||||
};
|
};
|
||||||
unordered_map<int,track_info> _codec_to_trackid;
|
unordered_map<int,track_info> _codec_to_trackid;
|
||||||
string _config_frame_cache;
|
List<Frame::Ptr> _frameCached;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
Loading…
Reference in New Issue
Block a user