From c29def92540bae63ef13f415424e36a5b434911e Mon Sep 17 00:00:00 2001 From: sladro Date: Tue, 16 Dec 2025 17:10:03 +0800 Subject: [PATCH] update plugins/publish/publish_node.cpp --- plugins/publish/publish_node.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/publish/publish_node.cpp b/plugins/publish/publish_node.cpp index 1bee911..55e7d52 100644 --- a/plugins/publish/publish_node.cpp +++ b/plugins/publish/publish_node.cpp @@ -136,8 +136,14 @@ public: std::memcpy(out.data, pkt.data.data(), pkt.data.size()); out.stream_index = stream_->index; out.flags = pkt.key ? AV_PKT_FLAG_KEY : 0; - out.pts = av_rescale_q(pkt.pts_ms, AVRational{1, 1000}, stream_->time_base); - out.dts = out.pts; + int64_t pts = av_rescale_q(pkt.pts_ms, AVRational{1, 1000}, stream_->time_base); + // Ensure monotonically increasing PTS/DTS + if (pts <= last_pts_) { + pts = last_pts_ + 1; + } + last_pts_ = pts; + out.pts = pts; + out.dts = pts; out.duration = av_rescale_q(1000 / std::max(1, fps_), AVRational{1, 1000}, stream_->time_base); int ret = av_interleaved_write_frame(fmt_, &out); @@ -203,6 +209,7 @@ private: bool ready_ = false; bool warned_ = false; uint64_t write_count_ = 0; + int64_t last_pts_ = -1; }; class AvMuxerManager {