add h264parser.CheckNALUsType for demuxer and muxer
This commit is contained in:
parent
f2ec2e0f97
commit
d08dd0b0a1
14
flv.go
14
flv.go
@ -77,10 +77,16 @@ func (self *Muxer) WritePacket(pkt av.Packet) (err error) {
|
||||
|
||||
switch stream.Type() {
|
||||
case av.H264:
|
||||
if typ := h264parser.CheckNALUsType(pkt.Data); typ != h264parser.NALU_RAW {
|
||||
err = fmt.Errorf("flv: h264 nalu format=%d invalid", typ)
|
||||
return
|
||||
}
|
||||
var b [4]byte
|
||||
pio.PutU32BE(b[:], uint32(len(pkt.Data)))
|
||||
tag := &flvio.Videodata{
|
||||
AVCPacketType: flvio.AVC_NALU,
|
||||
CodecID: flvio.VIDEO_H264,
|
||||
Data: pkt.Data,
|
||||
Datav: [][]byte{b[:], pkt.Data},
|
||||
CompositionTime: timeToTs(pkt.CompositionTime),
|
||||
}
|
||||
if pkt.IsKeyFrame {
|
||||
@ -245,7 +251,11 @@ func (self *Demuxer) ReadPacket() (pkt av.Packet, err error) {
|
||||
pkt.Idx = int8(self.videostreamidx)
|
||||
pkt.CompositionTime = tsToTime(tag.CompositionTime)
|
||||
pkt.IsKeyFrame = tag.FrameType == flvio.FRAME_KEY
|
||||
pkt.Data = tag.Data
|
||||
if typ := h264parser.CheckNALUsType(tag.Data); typ != h264parser.NALU_AVCC {
|
||||
err = fmt.Errorf("flv: h264 nalu format=%d invalid", typ)
|
||||
return
|
||||
}
|
||||
pkt.Data = tag.Data[4:]
|
||||
break loop
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user