From 0eedf34735e50272208c7b693e0146562d4eed66 Mon Sep 17 00:00:00 2001 From: Martin Riedl Date: Tue, 3 Dec 2024 19:29:14 +0100 Subject: [PATCH] new sample entry implementation for avc1 --- README.md | 7 +++++-- SampleDescriptionBox.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c9109c..7018331 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # goMP4 + [![pipeline status](https://gitlab.com/martinr92/gomp4/badges/main/pipeline.svg)](https://gitlab.com/martinr92/gomp4/commits/main) [![coverage report](https://gitlab.com/martinr92/gomp4/badges/main/coverage.svg)](https://gitlab.com/martinr92/gomp4/commits/main) mp4 implementation in golang based on spec ISO ICE 14496-12:2015 ## Parser + ```go parser := gomp4.NewParser(file) if err := parser.Parse(); err != nil { @@ -13,7 +15,8 @@ if err := parser.Parse(); err != nil { ``` ## Progress -Implementation progress + +Implementation progress of ISO ICE 14496-12:2015: | Chapter | Box Types | Parser | |----------------------------------------------------|----------------|-------:| @@ -34,7 +37,7 @@ Implementation progress | 8.4.5.2 Null Media Header Box | nmhd | - | | 8.4.6 Extended language tag | elng | - | | 8.5.1 Sample Table Box | stbl | 100% | -| 8.5.2 Sample Description Box | stsd | 20% | +| 8.5.2 Sample Description Box | stsd | 100% | | 8.5.3 Degradation Priority Box | stdp | - | | 8.6.1.2 Decoding Time to Sample Box | stts | - | | 8.6.1.3 Composition Time to Sample Box | ctts | - | diff --git a/SampleDescriptionBox.go b/SampleDescriptionBox.go index 90c6687..e061d7c 100644 --- a/SampleDescriptionBox.go +++ b/SampleDescriptionBox.go @@ -89,5 +89,40 @@ func ParseSampleDescriptionBox(parser *Parser, filePosition uint64, headerSize u // entry counter box.EntryCount = binary.BigEndian.Uint32(content[4:8]) + // parse child boxes + var err error + box.ChildBoxes, err = box.parseChildBoxes(parser, BoxTypeSampleDescription, filePosition, content[8:]) + if err != nil { + return box, err + } + + // validate entry count + if int(box.EntryCount) != len(box.ChildBoxes) { + return box, fmt.Errorf("invalid amount of boxes at %d; found %d but expected %d", filePosition, len(box.ChildBoxes), box.EntryCount) + } + + return box, nil +} + +type SampleEntry struct { + *Box + // is an integer that contains the index of the data reference to use to + // retrieve data associated with samples that use this sample description. Data references are + // stored in Data Reference Boxes. The index ranges from 1 to the number of data references. + DataReferenceIndex uint16 +} + +func ParseSampleEntry(filePosition uint64, headerSize uint32, content []byte) *SampleEntry { + box := &SampleEntry{ + Box: &Box{filePosition, headerSize}, + } + + // skip reserved + position := 2 * 8 + + // parse reference index + box.DataReferenceIndex = binary.BigEndian.Uint16(content[position : position+2]) + log.Println("data reference index", box.DataReferenceIndex) // TODO: remove me + return box }