From 02504b116966719be9287dd29ee7d800fecdcd23 Mon Sep 17 00:00:00 2001 From: deepch Date: Sat, 2 Apr 2022 14:55:57 +0300 Subject: [PATCH] add tag --- codec/aacparser/parser.go | 4 ++++ codec/h264parser/parser.go | 21 +++++++++++++++++++++ codec/h265parser/parser.go | 23 ++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/codec/aacparser/parser.go b/codec/aacparser/parser.go index c2ca3c7..a597422 100644 --- a/codec/aacparser/parser.go +++ b/codec/aacparser/parser.go @@ -290,6 +290,10 @@ func (self CodecData) SampleFormat() av.SampleFormat { return av.FLTP } +func (self CodecData) Tag() string { + return fmt.Sprintf("mp4a.40.%d", self.Config.ObjectType) +} + func (self CodecData) PacketDuration(data []byte) (dur time.Duration, err error) { dur = time.Duration(1024) * time.Second / time.Duration(self.Config.SampleRate) return diff --git a/codec/h264parser/parser.go b/codec/h264parser/parser.go index 042164f..1b52c4f 100644 --- a/codec/h264parser/parser.go +++ b/codec/h264parser/parser.go @@ -8,6 +8,7 @@ import ( "github.com/deepch/vdk/av" "github.com/deepch/vdk/utils/bits" "github.com/deepch/vdk/utils/bits/pio" + "time" ) const ( @@ -678,6 +679,26 @@ func (self CodecData) Height() int { return int(self.SPSInfo.Height) } +func (self CodecData) FPS() int { + return int(self.SPSInfo.FPS) +} + +func (self CodecData) Resolution() string { + return fmt.Sprintf("%vx%v", self.Width(), self.Height()) +} + +func (self CodecData) Tag() string { + return fmt.Sprintf("avc1.%02X%02X%02X", self.RecordInfo.AVCProfileIndication, self.RecordInfo.ProfileCompatibility, self.RecordInfo.AVCLevelIndication) +} + +func (self CodecData) Bandwidth() string { + return fmt.Sprintf("%v", (int(float64(self.Width())*(float64(1.71)*(30/float64(self.FPS())))))*1000) +} + +func (self CodecData) PacketDuration(data []byte) time.Duration { + return time.Duration(1000./float64(self.FPS())) * time.Millisecond +} + func NewCodecDataFromAVCDecoderConfRecord(record []byte) (self CodecData, err error) { self.Record = record if _, err = (&self.RecordInfo).Unmarshal(record); err != nil { diff --git a/codec/h265parser/parser.go b/codec/h265parser/parser.go index 79dbc6f..0521a09 100644 --- a/codec/h265parser/parser.go +++ b/codec/h265parser/parser.go @@ -4,10 +4,10 @@ import ( "bytes" "errors" "fmt" - "github.com/deepch/vdk/av" "github.com/deepch/vdk/utils/bits" "github.com/deepch/vdk/utils/bits/pio" + "time" ) type SPSInfo struct { @@ -34,6 +34,7 @@ type SPSInfo struct { generalProfileCompatibilityFlags uint32 generalConstraintIndicatorFlags uint64 generalLevelIDC uint + fps uint } const ( @@ -452,6 +453,26 @@ func (self CodecData) Height() int { return int(self.SPSInfo.Height) } +func (self CodecData) FPS() int { + return int(self.SPSInfo.fps) +} + +func (self CodecData) Resolution() string { + return fmt.Sprintf("%vx%v", self.Width(), self.Height()) +} + +func (self CodecData) Tag() string { + return fmt.Sprintf("hvc1.%02X%02X%02X", self.RecordInfo.AVCProfileIndication, self.RecordInfo.ProfileCompatibility, self.RecordInfo.AVCLevelIndication) +} + +func (self CodecData) Bandwidth() string { + return fmt.Sprintf("%v", (int(float64(self.Width())*(float64(1.71)*(30/float64(self.FPS())))))*1000) +} + +func (self CodecData) PacketDuration(data []byte) time.Duration { + return time.Duration(1000./float64(self.FPS())) * time.Millisecond +} + func NewCodecDataFromAVCDecoderConfRecord(record []byte) (self CodecData, err error) { self.Record = record if _, err = (&self.RecordInfo).Unmarshal(record); err != nil {