From a16b6cbc5973b7818bbd1c66a0b7edd3c2428da6 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 20 Mar 2022 14:52:15 +0800 Subject: [PATCH] =?UTF-8?q?mp4=E5=88=87=E7=89=87=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=AF=B9=E9=9F=B3=E8=A7=86=E9=A2=91=E4=BA=A4?= =?UTF-8?q?=E7=BB=87=E6=80=A7=E5=B7=AE=E7=9A=84=E6=B5=81=E7=9A=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Record/MP4Recorder.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index d5c4ae64..ede0d32d 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -96,19 +96,22 @@ void MP4Recorder::closeFile() { } bool MP4Recorder::inputFrame(const Frame::Ptr &frame) { - if (_last_dts == 0 || _last_dts > frame->dts()) { - //极少情况下dts时间戳可能回退 - _last_dts = frame->dts(); - } + if (!(_have_video && frame->getTrackType() == TrackAudio)) { + //如果有视频且输入的是音频,那么应该忽略切片逻辑 + if (_last_dts == 0 || _last_dts > frame->dts()) { + //极少情况下dts时间戳可能回退 + _last_dts = frame->dts(); + } - auto duration = frame->dts() - _last_dts; - if (!_muxer || ((duration > _max_second * 1000) && (!_have_video || (_have_video && frame->keyFrame())))) { - //成立条件 - //1、_muxer为空 - //2、到了切片时间,并且只有音频 - //3、到了切片时间,有视频并且遇到视频的关键帧 - _last_dts = 0; - createFile(); + auto duration = frame->dts() - _last_dts; + if (!_muxer || ((duration > _max_second * 1000) && (!_have_video || (_have_video && frame->keyFrame())))) { + //成立条件 + // 1、_muxer为空 + // 2、到了切片时间,并且只有音频 + // 3、到了切片时间,有视频并且遇到视频的关键帧 + _last_dts = 0; + createFile(); + } } if (_muxer) {