update plugins/publish/publish_node.cpp

This commit is contained in:
sladro 2025-12-16 17:05:39 +08:00
parent d98d2e0f2e
commit 206b2d3471

View File

@ -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<int64_t>(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<uint8_t> header_;
bool initialized_ = false;
uint64_t frame_count_ = 0;
};
#endif