diff --git a/plugins/publish/publish_node.cpp b/plugins/publish/publish_node.cpp index 57a7efc..1bee911 100644 --- a/plugins/publish/publish_node.cpp +++ b/plugins/publish/publish_node.cpp @@ -405,7 +405,28 @@ public: auto* pos = static_cast(mpp_packet_get_pos(packet)); 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 + // MPP_PACKET_FLAG_INTRA = 0x08, also check NAL type for H264 IDR (type 5) + RK_U32 flag = mpp_packet_get_flag(packet); + out.key = (flag & 0x08) != 0; // MPP_PACKET_FLAG_INTRA + // Fallback: check H264 NAL unit type if MPP flag not set + if (!out.key && len >= 5) { + // Find NAL start code and check type + for (size_t i = 0; i + 4 < len; ++i) { + if (pos[i] == 0 && pos[i+1] == 0 && pos[i+2] == 0 && pos[i+3] == 1) { + uint8_t nal_type = pos[i+4] & 0x1F; + if (nal_type == 5 || nal_type == 7) { // IDR or SPS + out.key = true; + break; + } + } else if (pos[i] == 0 && pos[i+1] == 0 && pos[i+2] == 1) { + uint8_t nal_type = pos[i+3] & 0x1F; + if (nal_type == 5 || nal_type == 7) { + out.key = true; + break; + } + } + } + } 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_);