From c6a8118c10a69c4288d1d912ddd2e80b98258f3b Mon Sep 17 00:00:00 2001 From: chdahuzi Date: Fri, 19 Jul 2024 17:10:22 +0800 Subject: [PATCH] =?UTF-8?q?fmp4=E5=B0=81=E8=A3=85=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E4=B8=80=E5=AE=9AI=E5=B8=A7=E9=97=B4=E9=9A=94=EF=BC=8C?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E5=88=B7=E6=96=B0segment=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=86=85=E5=AD=98=E4=B8=8A=E6=B6=A8=20(#3736)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Record/MP4Muxer.cpp | 15 +++++++++++++++ src/Record/MP4Muxer.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/Record/MP4Muxer.cpp b/src/Record/MP4Muxer.cpp index 46fda66f..6d686b50 100644 --- a/src/Record/MP4Muxer.cpp +++ b/src/Record/MP4Muxer.cpp @@ -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(track); CHECK(audio_track); diff --git a/src/Record/MP4Muxer.h b/src/Record/MP4Muxer.h index 4f764c3f..f0d7fce1 100644 --- a/src/Record/MP4Muxer.h +++ b/src/Record/MP4Muxer.h @@ -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: