diff --git a/plugins/publish/publish_node.cpp b/plugins/publish/publish_node.cpp index 68d8e36..57a7efc 100644 --- a/plugins/publish/publish_node.cpp +++ b/plugins/publish/publish_node.cpp @@ -143,10 +143,18 @@ public: int ret = av_interleaved_write_frame(fmt_, &out); av_packet_unref(&out); if (ret < 0 && !warned_) { + char errbuf[128]; + av_strerror(ret, errbuf, sizeof(errbuf)); std::cerr << "[publish] av_interleaved_write_frame failed for " << url_ << " ret=" - << ret << "\n"; + << ret << " (" << errbuf << ")\n"; warned_ = true; } + // Debug: log first few frames pts + if (write_count_ < 5 || write_count_ % 100 == 0) { + std::cout << "[publish] hls write frame " << write_count_ << " pts=" << pkt.pts_ms + << "ms key=" << pkt.key << " ret=" << ret << "\n"; + } + ++write_count_; return ret >= 0; } @@ -194,6 +202,7 @@ private: int fps_ = 25; bool ready_ = false; bool warned_ = false; + uint64_t write_count_ = 0; }; class AvMuxerManager { @@ -397,7 +406,10 @@ public: size_t len = mpp_packet_get_length(packet); out.data.assign(pos, pos + len); out.key = (mpp_packet_get_flag(packet) & 0x10) != 0; // INTRA flag - out.pts_ms = mpp_packet_get_pts(packet); + int64_t mpp_pts = mpp_packet_get_pts(packet); + // Use encoder's pts if valid, otherwise compute from frame count + out.pts_ms = mpp_pts > 0 ? mpp_pts : static_cast(frame_count_ * 1000 / fps_); + ++frame_count_; if (on_packet) on_packet(out); mpp_packet_deinit(&packet); break; @@ -471,6 +483,7 @@ private: int bitrate_bps_ = 4000000; std::vector header_; bool initialized_ = false; + uint64_t frame_count_ = 0; }; #endif