From 27b7043a0f92e3294bef89e4403edb970eeee845 Mon Sep 17 00:00:00 2001 From: iefimov Date: Wed, 9 Apr 2025 11:52:04 +0300 Subject: [PATCH 1/4] Parse stss atom --- atom/stbl.go | 5 +++++ atom/stss.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 atom/stss.go diff --git a/atom/stbl.go b/atom/stbl.go index d839b75..5bc2e88 100644 --- a/atom/stbl.go +++ b/atom/stbl.go @@ -9,6 +9,7 @@ type StblBox struct { *Box Stts *SttsBox Stsd *StsdBox + Stss *StssBox } func (b *StblBox) parse() error { @@ -23,6 +24,10 @@ func (b *StblBox) parse() error { case "stsd": b.Stsd = &StsdBox{Box: box} b.Stsd.parse() + + case "stss": + b.Stss = &StssBox{Box: box} + b.Stss.parse() } } return nil diff --git a/atom/stss.go b/atom/stss.go new file mode 100644 index 0000000..474eb91 --- /dev/null +++ b/atom/stss.go @@ -0,0 +1,39 @@ +package atom + +import ( + "encoding/binary" +) + +// StsdBox - Sample Description Box +// Box Type: stsd +// Container: Sample Table Box (stbl) +// Mandatory: Yes +// Quantity: Exactly one. +type StssBox struct { + *Box + Version byte + Flags uint32 + NumofEntries uint32 + SyncSampleTable []uint32 +} + +func (b *StssBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.NumofEntries = binary.BigEndian.Uint32(data[4:8]) + for i := 8; i < len(data); i += 4 { + b.SyncSampleTable = append(b.SyncSampleTable, uint32(binary.BigEndian.Uint32(data[i:i+4]))) + } + + /*boxes := readBoxes(b.Reader, b.Start+BoxHeaderSize+8, b.Size-BoxHeaderSize) // Skip extra 8 bytes. + + for _, box := range boxes { + switch box.Name { + case "avc1": + b.Avc1 = &Avc1Box{Box: box} + b.Avc1.parse() + } + }*/ + return nil +} From 323d28893bf5390a48c3e80a9bbf5be4303b3ebb Mon Sep 17 00:00:00 2001 From: iefimov Date: Wed, 9 Apr 2025 12:00:37 +0300 Subject: [PATCH 2/4] Fixed comments --- atom/stss.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/atom/stss.go b/atom/stss.go index 474eb91..55ebea2 100644 --- a/atom/stss.go +++ b/atom/stss.go @@ -4,16 +4,16 @@ import ( "encoding/binary" ) -// StsdBox - Sample Description Box -// Box Type: stsd -// Container: Sample Table Box (stbl) +// StssBox - Sync sample atom Box +// Box Type: stss +// Container: Sync sample atom Box (stss) // Mandatory: Yes // Quantity: Exactly one. type StssBox struct { *Box Version byte Flags uint32 - NumofEntries uint32 + EntriesNumber uint32 SyncSampleTable []uint32 } @@ -21,19 +21,10 @@ func (b *StssBox) parse() error { data := b.ReadBoxData() b.Version = data[0] b.Flags = binary.BigEndian.Uint32(data[0:4]) - b.NumofEntries = binary.BigEndian.Uint32(data[4:8]) + b.EntriesNumber = binary.BigEndian.Uint32(data[4:8]) for i := 8; i < len(data); i += 4 { b.SyncSampleTable = append(b.SyncSampleTable, uint32(binary.BigEndian.Uint32(data[i:i+4]))) } - /*boxes := readBoxes(b.Reader, b.Start+BoxHeaderSize+8, b.Size-BoxHeaderSize) // Skip extra 8 bytes. - - for _, box := range boxes { - switch box.Name { - case "avc1": - b.Avc1 = &Avc1Box{Box: box} - b.Avc1.parse() - } - }*/ return nil } From 3160badaff4a7dd60d82903595f3736b02ad304c Mon Sep 17 00:00:00 2001 From: iefimov Date: Wed, 9 Apr 2025 13:21:56 +0300 Subject: [PATCH 3/4] Parse ctts and stsc atoms --- atom/ctts.go | 24 ++++++++++++++++++++++++ atom/stbl.go | 8 ++++++++ atom/stsc.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 atom/ctts.go create mode 100644 atom/stsc.go diff --git a/atom/ctts.go b/atom/ctts.go new file mode 100644 index 0000000..24eb2e6 --- /dev/null +++ b/atom/ctts.go @@ -0,0 +1,24 @@ +package atom + +import "encoding/binary" + +// CttsBox - Composition offset atom Box +// Box Type: ctts +// Container: Composition offset atom Box (ctts) +// Mandatory: Yes +// Quantity: Exactly one. +type CttsBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 +} + +func (b *CttsBox) parse() error { + data := b.ReadBoxData() + + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + return nil +} diff --git a/atom/stbl.go b/atom/stbl.go index 5bc2e88..c5837db 100644 --- a/atom/stbl.go +++ b/atom/stbl.go @@ -10,6 +10,8 @@ type StblBox struct { Stts *SttsBox Stsd *StsdBox Stss *StssBox + Ctts *CttsBox + Stsc *StscBox } func (b *StblBox) parse() error { @@ -28,6 +30,12 @@ func (b *StblBox) parse() error { case "stss": b.Stss = &StssBox{Box: box} b.Stss.parse() + case "ctts": + b.Ctts = &CttsBox{Box: box} + b.Ctts.parse() + case "stsc": + b.Stsc = &StscBox{Box: box} + b.Stsc.parse() } } return nil diff --git a/atom/stsc.go b/atom/stsc.go new file mode 100644 index 0000000..b2e2fe3 --- /dev/null +++ b/atom/stsc.go @@ -0,0 +1,32 @@ +package atom + +import "encoding/binary" + +// StscBox - Sample-to-chunk atom Box +// Box Type: stsc +// Container: Sample-to-chunk atom Box (stsc) +// Mandatory: Yes +// Quantity: Exactly one. +type StscBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 + SampletoChunkData SampletoChunk +} +type SampletoChunk struct { + Firstchunk uint32 + SamplesPerChunk uint32 + SampleDescriptionID uint32 +} + +func (b *StscBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + b.SampletoChunkData.Firstchunk = binary.BigEndian.Uint32(data[8:12]) + b.SampletoChunkData.SamplesPerChunk = binary.BigEndian.Uint32(data[12:16]) + b.SampletoChunkData.SampleDescriptionID = binary.BigEndian.Uint32(data[16:20]) + return nil +} From 3f7f71774bef649eccdfebd1084611cc11ac6758 Mon Sep 17 00:00:00 2001 From: iefimov Date: Wed, 9 Apr 2025 14:52:52 +0300 Subject: [PATCH 4/4] Parsed Sample size atom stsz and chunk offset atom stco --- atom/stbl.go | 8 ++++++++ atom/stco.go | 28 ++++++++++++++++++++++++++++ atom/stsz.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 atom/stco.go create mode 100644 atom/stsz.go diff --git a/atom/stbl.go b/atom/stbl.go index c5837db..565bdae 100644 --- a/atom/stbl.go +++ b/atom/stbl.go @@ -12,6 +12,8 @@ type StblBox struct { Stss *StssBox Ctts *CttsBox Stsc *StscBox + Stsz *StszBox + Stco *StcoBox } func (b *StblBox) parse() error { @@ -36,6 +38,12 @@ func (b *StblBox) parse() error { case "stsc": b.Stsc = &StscBox{Box: box} b.Stsc.parse() + case "stsz": + b.Stsz = &StszBox{Box: box} + b.Stsz.parse() + case "stco": + b.Stco = &StcoBox{Box: box} + b.Stco.parse() } } return nil diff --git a/atom/stco.go b/atom/stco.go new file mode 100644 index 0000000..ac2aa42 --- /dev/null +++ b/atom/stco.go @@ -0,0 +1,28 @@ +package atom + +import "encoding/binary" + +// StcoBox - Chunk offset atom Box +// Box Type: stco +// Container: Chunk offset atom Box (stco) +// Mandatory: Yes +// Quantity: Exactly one. +type StcoBox struct { + *Box + Version byte + Flags uint32 + EntryCount uint32 + ChunkOffsetTable []uint32 +} + +func (b *StcoBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.EntryCount = binary.BigEndian.Uint32(data[4:8]) + + for i := 0; i < int(b.EntryCount); i++ { + b.ChunkOffsetTable = append(b.ChunkOffsetTable, binary.BigEndian.Uint32(data[i*4+8:i*4+12])) + } + return nil +} diff --git a/atom/stsz.go b/atom/stsz.go new file mode 100644 index 0000000..63b3b68 --- /dev/null +++ b/atom/stsz.go @@ -0,0 +1,31 @@ +package atom + +import "encoding/binary" + +// StszBox - Sample size atom Box +// Box Type: sttz +// Container: Sample Size Table Box (stsz) +// Mandatory: Yes +// Quantity: Exactly one. +type StszBox struct { + *Box + Version byte + Flags uint32 + SampleSize uint32 + EntryCount uint32 + SampleSizeTable []uint32 +} + +func (b *StszBox) parse() error { + data := b.ReadBoxData() + b.Version = data[0] + b.Flags = binary.BigEndian.Uint32(data[0:4]) + b.SampleSize = binary.BigEndian.Uint32(data[4:8]) + b.EntryCount = binary.BigEndian.Uint32(data[8:12]) + if b.SampleSize == 0 { + for i := 0; i < int(b.EntryCount); i++ { + b.SampleSizeTable = append(b.SampleSizeTable, binary.BigEndian.Uint32(data[i*4+12:i*4+16])) + } + } + return nil +}