From ca8bedd8d314864438176874341f3d8cd1ba572e Mon Sep 17 00:00:00 2001 From: Martin Riedl Date: Fri, 27 Dec 2024 18:39:52 +0100 Subject: [PATCH] feat: track extends box --- README.md | 2 +- TrackExtendsBox.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 TrackExtendsBox.go diff --git a/README.md b/README.md index e48f07b..230cee8 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Implementation progress of ISO/IEC 14496-12:2015: | 8.7.9 Sample Auxiliary Information Offsets Box | saio | - | | 8.8.1 Movie Extends Box | mvex | 100% | | 8.8.2 Movie Extends Header Box | mehd | - | -| 8.8.3 Track Extends Box | trex | - | +| 8.8.3 Track Extends Box | trex | 100% | | 8.8.4 Movie Fragment Box | moof | 100% | | 8.8.5 Movie Fragment Header Box | mfhd | 100% | | 8.8.6 Track Fragment Box | traf | 100% | diff --git a/TrackExtendsBox.go b/TrackExtendsBox.go new file mode 100644 index 0000000..47994ee --- /dev/null +++ b/TrackExtendsBox.go @@ -0,0 +1,60 @@ +// Copyright 2024 Martin Riedl +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gomp4 + +import ( + "encoding/binary" +) + +// TrackExtendsBox Track Extends Box struct +// +// 8.8.3 Track Extends Box +// +// This sets up default values used by the movie fragments. By setting defaults in this way, space and +// complexity can be saved in each Track Fragment Box. +type TrackExtendsBox struct { + *FullBox + // identifies the track; this shall be the track ID of a track in the Movie Box + TrackID uint32 + DefaultSampleDescriptionIndex uint32 + DefaultSampleDuration uint32 + DefaultSampleSize uint32 + DefaultSampleFlags uint32 +} + +const BoxTypeTrackExtends = "trex" + +func init() { + BoxDefinitions = append(BoxDefinitions, BoxDefinition{ + Type: BoxTypeTrackExtends, + ParentTypes: []string{BoxTypeMovieExtends}, + Parser: ParseTrackExtendsBox, + }) +} + +// ParseTrackExtendsBox creates a new track extends box struct based on bytes +func ParseTrackExtendsBox(parser *Parser, filePosition uint64, headerSize uint32, content []byte) (any, error) { + box := &TrackExtendsBox{ + FullBox: newFullBox(&Box{filePosition, headerSize}, content[0:4]), + } + + box.TrackID = binary.BigEndian.Uint32(content[4:8]) + box.DefaultSampleDescriptionIndex = binary.BigEndian.Uint32(content[8:12]) + box.DefaultSampleDuration = binary.BigEndian.Uint32(content[12:16]) + box.DefaultSampleSize = binary.BigEndian.Uint32(content[16:20]) + box.DefaultSampleFlags = binary.BigEndian.Uint32(content[20:24]) + + return box, nil +}