mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
fmp4封装超过一定I帧间隔,强制刷新segment,防止内存上涨 (#3736)
This commit is contained in:
parent
e3dcd9119e
commit
c6a8118c10
@ -99,6 +99,20 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) {
|
||||
_started = true;
|
||||
}
|
||||
|
||||
// fmp4封装超过一定I帧间隔,强制刷新segment,防止内存上涨
|
||||
if (frame->getTrackType() == TrackVideo && _mov_writter->fmp4) {
|
||||
if (frame->keyFrame()) {
|
||||
_non_iframe_video_count = 0;
|
||||
} else {
|
||||
_non_iframe_video_count++;
|
||||
}
|
||||
|
||||
if (_non_iframe_video_count > 200) {
|
||||
saveSegment();
|
||||
_non_iframe_video_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// mp4文件时间戳需要从0开始
|
||||
auto &track = it->second;
|
||||
switch (frame->getCodecId()) {
|
||||
@ -164,6 +178,7 @@ bool MP4MuxerInterface::addTrack(const Track::Ptr &track) {
|
||||
}
|
||||
_tracks[track->getIndex()].track_id = track_id;
|
||||
_have_video = true;
|
||||
_non_iframe_video_count = 0;
|
||||
} else if (track->getTrackType() == TrackAudio) {
|
||||
auto audio_track = dynamic_pointer_cast<AudioTrack>(track);
|
||||
CHECK(audio_track);
|
||||
|
@ -72,6 +72,7 @@ private:
|
||||
bool _started = false;
|
||||
bool _have_video = false;
|
||||
MP4FileIO::Writer _mov_writter;
|
||||
int _non_iframe_video_count; // 非I帧个数
|
||||
|
||||
class FrameMergerImp : public FrameMerger {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user