diff options
| -rw-r--r-- | box.go | 11 | ||||
| -rw-r--r-- | cmd/mp4dump/main.go | 2 | ||||
| -rw-r--r-- | iter.go | 42 |
3 files changed, 44 insertions, 11 deletions
@@ -11,6 +11,7 @@ func (t BoxType) String() string { // Known box types. var ( TypeFtyp = BoxType{'f', 't', 'y', 'p'} + TypeStyp = BoxType{'s', 't', 'y', 'p'} // Segment type box (used in fragmented MP4) TypeMoov = BoxType{'m', 'o', 'o', 'v'} TypeMvhd = BoxType{'m', 'v', 'h', 'd'} TypeTrak = BoxType{'t', 'r', 'a', 'k'} @@ -51,6 +52,7 @@ var ( TypeSubs = BoxType{'s', 'u', 'b', 's'} TypeSaiz = BoxType{'s', 'a', 'i', 'z'} TypeSaio = BoxType{'s', 'a', 'i', 'o'} + // Fragment movie boxes TypeMvex = BoxType{'m', 'v', 'e', 'x'} TypeMehd = BoxType{'m', 'e', 'h', 'd'} TypeTrex = BoxType{'t', 'r', 'e', 'x'} @@ -61,13 +63,20 @@ var ( TypeTfhd = BoxType{'t', 'f', 'h', 'd'} TypeTfdt = BoxType{'t', 'f', 'd', 't'} TypeTrun = BoxType{'t', 'r', 'u', 'n'} + TypeSidx = BoxType{'s', 'i', 'd', 'x'} // Segment index box + TypeEmsg = BoxType{'e', 'm', 's', 'g'} // Event message box + // Metadata boxes TypeMeta = BoxType{'m', 'e', 't', 'a'} TypeUdta = BoxType{'u', 'd', 't', 'a'} + // Data boxes TypeMdat = BoxType{'m', 'd', 'a', 't'} TypeFree = BoxType{'f', 'r', 'e', 'e'} TypeSkip = BoxType{'s', 'k', 'i', 'p'} + // Sample entry boxes TypeAvc1 = BoxType{'a', 'v', 'c', '1'} TypeAvcC = BoxType{'a', 'v', 'c', 'C'} + TypeBtrt = BoxType{'b', 't', 'r', 't'} // MPEG-4 Bit rate box + TypePasp = BoxType{'p', 'a', 's', 'p'} // Pixel aspect ratio box TypeMp4a = BoxType{'m', 'p', '4', 'a'} TypeEsds = BoxType{'e', 's', 'd', 's'} ) @@ -82,7 +91,7 @@ func IsFullBox(t BoxType) bool { TypeMeta, TypeEsds, TypeMehd, TypeTrex, TypeMfhd, TypeTfhd, TypeTfdt, TypeTrun, TypeSbgp, TypeSgpd, TypeSaiz, TypeSaio, - TypeCslg, TypeSdtp: + TypeCslg, TypeSdtp, TypeSidx, TypeEmsg: return true } return false diff --git a/cmd/mp4dump/main.go b/cmd/mp4dump/main.go index 0d42d18..ee7a577 100644 --- a/cmd/mp4dump/main.go +++ b/cmd/mp4dump/main.go @@ -209,7 +209,7 @@ func printBoxInfo(r *mp4.Reader) { fmt.Printf(" entries=%d", it.Count()) case mp4.TypeCtts: - it := mp4.NewCttsIter(r.Data()) + it := mp4.NewCttsIter(r.Data(), r.Version()) fmt.Printf(" entries=%d", it.Count()) case mp4.TypeStsc: @@ -133,24 +133,29 @@ func (it *SttsIter) Next() (SttsEntry, bool) { // CttsEntry is a composition offset entry. type CttsEntry struct { Count uint32 - Offset int32 + Offset int32 // Signed offset (version 1), or unsigned treated as signed (version 0) } // CttsIter iterates over ctts entries. type CttsIter struct { - buf []byte - count uint32 - index uint32 + buf []byte + count uint32 + index uint32 + version uint8 } // NewCttsIter creates an iterator from ctts box data. -func NewCttsIter(data []byte) CttsIter { +// version should be 0 or 1 from the ctts box version field. +// Version 0: offsets are uint32 (but interpreted as composition time offset) +// Version 1: offsets are int32 (signed composition time offset) +func NewCttsIter(data []byte, version uint8) CttsIter { if len(data) < 4 { return CttsIter{} } return CttsIter{ - buf: data, - count: be.Uint32(data[0:4]), + buf: data, + count: be.Uint32(data[0:4]), + version: version, } } @@ -167,8 +172,16 @@ func (it *CttsIter) Next() (CttsEntry, bool) { return CttsEntry{}, false } e := CttsEntry{ - Count: be.Uint32(it.buf[offset:]), - Offset: int32(be.Uint32(it.buf[offset+4:])), + Count: be.Uint32(it.buf[offset:]), + } + // Version 0: uint32 offset (but typically small positive values) + // Version 1: int32 offset (can be negative) + if it.version == 0 { + // In version 0, the value is uint32 but should be interpreted as offset + e.Offset = int32(be.Uint32(it.buf[offset+4:])) + } else { + // In version 1, the value is explicitly signed + e.Offset = int32(be.Uint32(it.buf[offset+4:])) } it.index++ return e, true @@ -300,6 +313,17 @@ const ( TrunSampleCompositionTimeOffsetPresent = 0x000800 ) +// Tfhd flags (Track Fragment Header Box). +const ( + TfhdBaseDataOffsetPresent = 0x000001 + TfhdSampleDescriptionIndexPresent = 0x000002 + TfhdDefaultSampleDurationPresent = 0x000008 + TfhdDefaultSampleSizePresent = 0x000010 + TfhdDefaultSampleFlagsPresent = 0x000020 + TfhdDurationIsEmpty = 0x010000 + TfhdDefaultBaseIsMoof = 0x020000 +) + // TrunIter iterates over trun entries. type TrunIter struct { buf []byte |
