test annex

This commit is contained in:
deepch
2022-04-27 23:59:59 +03:00
parent 02504b1169
commit 7d87dbe2dd
4 changed files with 33 additions and 10 deletions

View File

@@ -22,8 +22,8 @@ type Demuxer struct {
pmt *tsio.PMT
streams []*Stream
tshdr []byte
stage int
AnnexB bool
stage int
}
func NewDemuxer(r io.Reader) *Demuxer {
@@ -252,6 +252,7 @@ func (self *Stream) payloadEnd() (n int, err error) {
case tsio.ElementaryStreamTypeH264:
nalus, _ := h264parser.SplitNALUs(payload)
var sps, pps []byte
for _, nalu := range nalus {
if len(nalu) > 0 {
naltype := nalu[0] & 0x1f
@@ -262,15 +263,25 @@ func (self *Stream) payloadEnd() (n int, err error) {
pps = nalu
case h264parser.IsDataNALU(nalu):
// raw nalu to avcc
b := make([]byte, 4+len(nalu))
pio.PutU32BE(b[0:4], uint32(len(nalu)))
copy(b[4:], nalu)
self.addPacket(b, time.Duration(0))
n++
if !self.demuxer.AnnexB {
b := make([]byte, 4+len(nalu))
pio.PutU32BE(b[0:4], uint32(len(nalu)))
copy(b[4:], nalu)
self.addPacket(b, time.Duration(0))
n++
}
}
}
}
if self.demuxer.AnnexB {
b := make([]byte, 4+len(payload))
pio.PutU32BE(b[0:4], uint32(len(payload)))
copy(b[4:], payload)
self.addPacket(b, time.Duration(0))
n++
}
if self.CodecData == nil && len(sps) > 0 && len(pps) > 0 {
if self.CodecData, err = h264parser.NewCodecDataFromSPSAndPPS(sps, pps); err != nil {
return