Restore fix for Chinese buggy cameras

This commit is contained in:
Alexey Khit
2023-09-06 13:15:04 +03:00
parent 064ffef462
commit 124398115e
2 changed files with 21 additions and 2 deletions
+19
View File
@@ -139,3 +139,22 @@ func IndexFrame(b []byte) int {
return -1
}
func FixAnnexBInAVCC(b []byte) []byte {
for i := 0; i < len(b); {
if i+4 >= len(b) {
break
}
size := bytes.Index(b[i+4:], []byte{0, 0, 0, 1})
if size < 0 {
size = len(b) - (i + 4)
}
binary.BigEndian.PutUint32(b[i:], uint32(size))
i += size + 4
}
return b
}