Create AnnexB2AVC func

This commit is contained in:
Alexey Khit
2023-02-11 09:54:34 +03:00
parent 80f77d28c8
commit 4cbbb5407c
2 changed files with 21 additions and 18 deletions
+20
View File
@@ -1,11 +1,31 @@
package h264
import (
"bytes"
"encoding/binary"
"github.com/AlexxIT/go2rtc/pkg/streamer"
"github.com/pion/rtp"
)
func AnnexB2AVC(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
}
func EncodeAVC(nals ...[]byte) (avc []byte) {
var i, n int