From b3a169744fc46373eb49ce6427ab9a771d6278b0 Mon Sep 17 00:00:00 2001 From: erkin-io <9297263+erkin-io@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:44:11 +0100 Subject: [PATCH 1/2] Reading the RTMP key frame type from the NAL header Co-Authored-By: Claude Opus 5.5 --- src/rtmp.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rtmp.c b/src/rtmp.c index c9e21b1e..f6e5cca6 100644 --- a/src/rtmp.c +++ b/src/rtmp.c @@ -469,9 +469,20 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) { } else { if (type == NalUnitType_SPS) flv_set_sps((char *)nal_start, nal_len); if (type == NalUnitType_PPS) flv_set_pps((char *)nal_start, nal_len); - if (type == NalUnitType_CodedSliceIdr || type == NalUnitType_CodedSliceNonIdr) { - is_slice = true; - is_idr = (type == NalUnitType_CodedSliceIdr); + /* Take the slice type from the NAL header itself as well: some + * HALs (Fullhan V200) do not give the key-frame slice type 5 in + * the pack table, so no key frame was ever seen here and the + * video sequence header was never sent. */ + { + uint32_t sc = 0; + if (nal_len > 4 && nal_start[0] == 0 && nal_start[1] == 0) + sc = (nal_start[2] == 1) ? 3 : ((nal_start[2] == 0 && nal_start[3] == 1) ? 4 : 0); + int real = (nal_len > sc) ? (nal_start[sc] & 0x1F) : 0; + if (real == NalUnitType_CodedSliceIdr || real == NalUnitType_CodedSliceNonIdr || + type == NalUnitType_CodedSliceIdr || type == NalUnitType_CodedSliceNonIdr) { + is_slice = true; + is_idr = (real == NalUnitType_CodedSliceIdr || type == NalUnitType_CodedSliceIdr); + } } } From ce0869aebfa9f919790d875d4171a7b6e4dd4de7 Mon Sep 17 00:00:00 2001 From: erkin-io <9297263+erkin-io@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:15:13 +0100 Subject: [PATCH 2/2] Leaving the start code out of RTMP video NAL units FLV carries each NAL unit behind a 4-byte length. The slices were written with their Annex-B start code still in front (all 274 in a 12 s capture); they are now written without it, as the SPS and PPS already are. Co-Authored-By: Claude Opus 5.5 --- src/rtmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rtmp.c b/src/rtmp.c index f6e5cca6..feb8e682 100644 --- a/src/rtmp.c +++ b/src/rtmp.c @@ -516,6 +516,14 @@ int rtmp_ingest_video(hal_vidpack *packet, int is_h265) { } if (seq_header_sent) { + /* FLV carries each NAL unit behind a 4-byte length, without + * the Annex-B start code that most HALs leave in front */ + if (nal_len > 4 && nal_start[0] == 0 && nal_start[1] == 0) { + uint32_t sc = (nal_start[2] == 1) ? 3 : + ((nal_start[2] == 0 && nal_start[3] == 1) ? 4 : 0); + nal_start += sc; + nal_len -= sc; + } if (flv_set_slice((char *)nal_start, nal_len, is_idr) == BUF_OK && flv_set_state(&flv_state) == BUF_OK) { struct BitBuf tags;