From 1355172fa2aa5e55eff3bd66a8d27d6de1d24c54 Mon Sep 17 00:00:00 2001 From: xingqiao Date: Mon, 11 Mar 2024 17:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=86=E9=A2=91=E6=B5=81?= =?UTF-8?q?=E5=AD=98=E5=9C=A8b=E5=B8=A7=E6=97=B6=EF=BC=8C=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=BF=BB=E8=BD=AC=E5=AF=BC=E8=87=B4=E7=9A=84=E5=88=87?= =?UTF-8?q?=E7=89=87=E7=B2=BE=E5=BA=A6=E5=81=8F=E5=B7=AE=E5=BE=88=E5=A4=A7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Record/MP4Recorder.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Record/MP4Recorder.cpp b/src/Record/MP4Recorder.cpp index f54c1d42..c8cee016 100644 --- a/src/Record/MP4Recorder.cpp +++ b/src/Record/MP4Recorder.cpp @@ -117,11 +117,13 @@ bool MP4Recorder::inputFrame(const Frame::Ptr &frame) { if (!(_have_video && frame->getTrackType() == TrackAudio)) { //如果有视频且输入的是音频,那么应该忽略切片逻辑 if (_last_dts == 0 || _last_dts > frame->dts()) { - //极少情况下dts时间戳可能回退 - _last_dts = frame->dts(); + //b帧情况下dts时间戳可能回退 + _last_dts = MAX(frame->dts(), _last_dts); + } + auto duration = 5; // 默认至少一帧5ms + if (frame->dts() > 0 && frame->dts() > _last_dts) { + duration = MAX(duration, frame->dts() - _last_dts); } - - auto duration = frame->dts() - _last_dts; if (!_muxer || ((duration > _max_second * 1000) && (!_have_video || (_have_video && frame->keyFrame())))) { //成立条件 // 1、_muxer为空