From f4b6a6bd40a43e3852b0280d3271fb9011c02554 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Thu, 16 Dec 2021 10:50:31 +0800 Subject: [PATCH] =?UTF-8?q?MP4:=20=E4=BF=AE=E5=A4=8Dmp4=E8=A7=A3=E5=A4=8D?= =?UTF-8?q?=E7=94=A8=E5=AE=9A=E6=97=B6=E5=99=A8=E7=B2=BE=E5=BA=A6=E5=A4=AA?= =?UTF-8?q?=E9=AB=98=E6=97=B6=E8=AF=BB=E5=8F=96=E6=96=87=E4=BB=B6=E5=A4=AA?= =?UTF-8?q?=E5=BF=AB=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Record/MP4Reader.cpp | 7 +++---- src/Record/MP4Reader.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Record/MP4Reader.cpp b/src/Record/MP4Reader.cpp index b5d43aee..a69ab28f 100644 --- a/src/Record/MP4Reader.cpp +++ b/src/Record/MP4Reader.cpp @@ -59,17 +59,15 @@ bool MP4Reader::readSample() { bool keyFrame = false; bool eof = false; - while (!eof) { + while (!eof && _last_dts < getCurrentStamp()) { auto frame = _demuxer->readFrame(keyFrame, eof); if (!frame) { continue; } + _last_dts = frame->dts(); if (_muxer) { _muxer->inputFrame(frame); } - if (frame->dts() > getCurrentStamp()) { - break; - } } GET_CONFIG(bool, fileRepeat, Record::kFileRepeat); @@ -129,6 +127,7 @@ uint32_t MP4Reader::getCurrentStamp() { void MP4Reader::setCurrentStamp(uint32_t new_stamp){ auto old_stamp = getCurrentStamp(); _seek_to = new_stamp; + _last_dts = new_stamp; _seek_ticker.resetTime(); if (old_stamp != new_stamp && _muxer) { //时间轴未拖动时不操作 diff --git a/src/Record/MP4Reader.h b/src/Record/MP4Reader.h index 4978e78a..29337235 100644 --- a/src/Record/MP4Reader.h +++ b/src/Record/MP4Reader.h @@ -60,6 +60,7 @@ private: bool _have_video = false; bool _paused = false; float _speed = 1.0; + uint32_t _last_dts = 0; uint32_t _seek_to; string _file_path; recursive_mutex _mtx;