diff --git a/src/Record/TsMuxer.cpp b/src/Record/TsMuxer.cpp index 38ea3459..97bb39a8 100644 --- a/src/Record/TsMuxer.cpp +++ b/src/Record/TsMuxer.cpp @@ -110,6 +110,7 @@ void TsMuxer::inputFrame(const Frame::Ptr &frame) { _is_idr_fast_packet = have_idr; mpeg_ts_write(_context, track_info.track_id, have_idr ? 0x0001 : 0, pts_out * 90LL, dts_out * 90LL, buffer->data(), buffer->size()); + flushCache(); }); break; } @@ -129,6 +130,7 @@ void TsMuxer::inputFrame(const Frame::Ptr &frame) { } mpeg_ts_write(_context, track_info.track_id, frame->keyFrame() ? 0x0001 : 0, pts_out * 90LL, dts_out * 90LL, frame->data(), frame->size()); + flushCache(); break; } } @@ -154,8 +156,7 @@ void TsMuxer::init() { }, [](void *param, const void *packet, size_t bytes) { TsMuxer *muxer = (TsMuxer *) param; - muxer->onTs(packet, bytes, muxer->_timestamp, muxer->_is_idr_fast_packet); - muxer->_is_idr_fast_packet = false; + muxer->onTs_l(packet, bytes); return 0; } }; @@ -164,6 +165,16 @@ void TsMuxer::init() { } } +void TsMuxer::onTs_l(const void *packet, size_t bytes) { + _cache.append((char *) packet, bytes); +} + +void TsMuxer::flushCache() { + onTs(_cache.data(), _cache.size(), _timestamp, _is_idr_fast_packet); + _cache.clear(); + _is_idr_fast_packet = false; +} + void TsMuxer::uninit() { if (_context) { mpeg_ts_destroy(_context); diff --git a/src/Record/TsMuxer.h b/src/Record/TsMuxer.h index 1a7ad101..ea540346 100644 --- a/src/Record/TsMuxer.h +++ b/src/Record/TsMuxer.h @@ -57,6 +57,8 @@ private: void uninit(); //音视频时间戳同步用 void stampSync(); + void onTs_l(const void *packet, size_t bytes); + void flushCache(); private: bool _have_video = false; @@ -70,6 +72,7 @@ private: }; unordered_map _codec_to_trackid; FrameMerger _frame_merger{FrameMerger::h264_prefix}; + BufferLikeString _cache; }; }//namespace mediakit