From 26e0ac410f5e3f4aff75c2586d68ecc7f2355693 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 14 Apr 2024 15:35:53 +0200 Subject: [PATCH] Fix keyframe detection for VP8 and VP9. --- codecs/codecs.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codecs/codecs.go b/codecs/codecs.go index 91690a5..ffbda0f 100644 --- a/codecs/codecs.go +++ b/codecs/codecs.go @@ -266,10 +266,10 @@ func PacketFlags(codec string, buf []byte) (Flags, error) { if err != nil { return flags, err } - flags.Start = vp8.S != 0 && vp8.PID == 0 flags.End = packet.Marker - flags.Keyframe = vp8.S != 0 && (vp8.Payload[0]&0x1) == 0 + flags.Keyframe = vp8.S != 0 && vp8.PID == 0 && + len(vp8.Payload) > 0 && (vp8.Payload[0]&0x1) == 0 flags.Pid = vp8.PictureID flags.Tid = vp8.TID flags.TidUpSync = flags.Keyframe || vp8.Y == 1 @@ -289,7 +289,8 @@ func PacketFlags(codec string, buf []byte) (Flags, error) { } flags.Start = vp9.B flags.End = vp9.E - if (vp9.Payload[0] & 0xc0) == 0x80 { + if vp9.B && len(vp9.Payload) > 0 && + (vp9.Payload[0] & 0xc0) == 0x80 { profile := (vp9.Payload[0] >> 4) & 0x3 if profile != 3 { flags.Keyframe = (vp9.Payload[0] & 0xC) == 0