fmp4封装超过一定I帧间隔,强制刷新segment,防止内存上涨 (#3736)

This commit is contained in:
chdahuzi 2024-07-19 17:10:22 +08:00 committed by GitHub
parent e3dcd9119e
commit c6a8118c10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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: