Create AnnexB2AVC func
This commit is contained in:
@@ -1,11 +1,31 @@
|
|||||||
package h264
|
package h264
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
||||||
"github.com/pion/rtp"
|
"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) {
|
func EncodeAVC(nals ...[]byte) (avc []byte) {
|
||||||
var i, n int
|
var i, n int
|
||||||
|
|
||||||
|
|||||||
+1
-18
@@ -1,7 +1,6 @@
|
|||||||
package h264
|
package h264
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
"github.com/AlexxIT/go2rtc/pkg/streamer"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
@@ -83,23 +82,7 @@ func RTPDepay(track *streamer.Track) streamer.WrapperFunc {
|
|||||||
// some Chinese buggy cameras has single packet with SPS+PPS+IFrame separated by 00 00 00 01
|
// some Chinese buggy cameras has single packet with SPS+PPS+IFrame separated by 00 00 00 01
|
||||||
// https://github.com/AlexxIT/WebRTC/issues/391
|
// https://github.com/AlexxIT/WebRTC/issues/391
|
||||||
// https://github.com/AlexxIT/WebRTC/issues/392
|
// https://github.com/AlexxIT/WebRTC/issues/392
|
||||||
for i := 0; i < len(payload); {
|
AnnexB2AVC(payload)
|
||||||
if i+4 >= len(payload) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
size := bytes.Index(payload[i+4:], []byte{0, 0, 0, 1})
|
|
||||||
if size < 0 {
|
|
||||||
if i == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
size = len(payload) - (i + 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
binary.BigEndian.PutUint32(payload[i:], uint32(size))
|
|
||||||
|
|
||||||
i += size + 4
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf("[AVC] %v, len: %d, ts: %10d, seq: %d", Types(payload), len(payload), packet.Timestamp, packet.SequenceNumber)
|
//log.Printf("[AVC] %v, len: %d, ts: %10d, seq: %d", Types(payload), len(payload), packet.Timestamp, packet.SequenceNumber)
|
||||||
|
|||||||
Reference in New Issue
Block a user