Add SPS parser and AVC/HVC conf encoders

This commit is contained in:
Alexey Khit
2023-08-14 11:55:08 +03:00
parent 3a40515a90
commit de6bb33f01
12 changed files with 302 additions and 599 deletions
+11 -14
View File
@@ -2,13 +2,14 @@ package mp4
import (
"encoding/hex"
"errors"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/h264"
"github.com/AlexxIT/go2rtc/pkg/h264/avc"
"github.com/AlexxIT/go2rtc/pkg/h265"
"github.com/AlexxIT/go2rtc/pkg/h265/hvc"
"github.com/AlexxIT/go2rtc/pkg/iso"
"github.com/deepch/vdk/codec/h264parser"
"github.com/deepch/vdk/codec/h265parser"
"github.com/pion/rtp"
)
@@ -73,15 +74,13 @@ func (m *Muxer) GetInit(codecs []*core.Codec) ([]byte, error) {
pps = []byte{0x68, 0xce, 0x38, 0x80}
}
codecData, err := h264parser.NewCodecDataFromSPSAndPPS(sps, pps)
if err != nil {
return nil, err
s := avc.DecodeSPS(sps)
if s == nil {
return nil, errors.New("mp4: can't parse SPS")
}
mv.WriteVideoTrack(
uint32(i+1), codec.Name, codec.ClockRate,
uint16(codecData.Width()), uint16(codecData.Height()),
codecData.AVCDecoderConfRecordBytes(),
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Heigth(), avc.EncodeConfig(sps, pps),
)
case core.CodecH265:
@@ -97,15 +96,13 @@ func (m *Muxer) GetInit(codecs []*core.Codec) ([]byte, error) {
pps = []byte{0x44, 0x01, 0xc0, 0x73, 0xc0, 0x4c, 0x90}
}
codecData, err := h265parser.NewCodecDataFromVPSAndSPSAndPPS(vps, sps, pps)
if err != nil {
return nil, err
s := avc.DecodeSPS(sps)
if s == nil {
return nil, errors.New("mp4: can't parse SPS")
}
mv.WriteVideoTrack(
uint32(i+1), codec.Name, codec.ClockRate,
uint16(codecData.Width()), uint16(codecData.Height()),
codecData.AVCDecoderConfRecordBytes(),
uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Heigth(), hvc.EncodeConfig(vps, sps, pps),
)
case core.CodecAAC: