aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-02-14 01:40:27 +0100
committerOnur Gündüz <ogunduz@gmail.com>2026-02-14 01:40:27 +0100
commit3302c4a4518312df79eb6b6b72a98b7707803750 (patch)
tree738de7e92f36714870120a2bbaedc589a08f8b0f
parent0a46cca30ca69cdb97a6fe1f807ef7eacc2ae0f3 (diff)
downloadmp4-3302c4a4518312df79eb6b6b72a98b7707803750.tar.gz
mp4-3302c4a4518312df79eb6b6b72a98b7707803750.zip
Rebranding
-rw-r--r--README.md4
-rw-r--r--box.go4
-rw-r--r--cmd/mfdump/README.md (renamed from cmd/mp4dump/README.md)8
-rw-r--r--cmd/mfdump/main.go (renamed from cmd/mp4dump/main.go)118
-rw-r--r--descriptor.go2
-rw-r--r--go.mod2
-rw-r--r--iter.go2
-rw-r--r--reader.go4
-rw-r--r--scanner.go8
-rw-r--r--writer.go9
10 files changed, 79 insertions, 82 deletions
diff --git a/README.md b/README.md
index 452f69f..3bc5815 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-# mp4
+# isobmff
-Pure Go implementation of ISO Base Media File Format (ISO/IEC 14496-12) box codec.
+Go implementation of ISO Base Media File Format (ISO/IEC 14496-12) box codec and accompanying tools.
diff --git a/box.go b/box.go
index 0c836b0..3ce86f7 100644
--- a/box.go
+++ b/box.go
@@ -1,5 +1,5 @@
-// Package mp4 implements encoding and decoding of ISO Base Media File Format (MP4) boxes.
-package mp4
+// Package isobmff implements encoding and decoding of ISO Base Media File Format (ISOBMFF) boxes.
+package isobmff
// BoxType is a 4-byte box type identifier.
type BoxType [4]byte
diff --git a/cmd/mp4dump/README.md b/cmd/mfdump/README.md
index ce25882..770e468 100644
--- a/cmd/mp4dump/README.md
+++ b/cmd/mfdump/README.md
@@ -1,13 +1,13 @@
-# mp4dump
+# mfdump
-`mp4dump` reads an MP4 file and dumps its box structure in a human-readable format.
+`mfdump` reads a media file (e.g., MP4) and dumps its box structure in a human-readable format.
**Example:**
-Pipe the output of `mp4dump` to [`indentree`](https://github.com/tetsuo/indentree) to visualize the box hierarchy:
+Pipe the output of `mfdump` to [`indentree`](https://github.com/tetsuo/indentree) to visualize the box hierarchy:
```
-mp4dump "big-buck-bunny-1080p-60fps-30sec.mp4" | indentree
+mfdump "big-buck-bunny-1080p-60fps-30sec.mp4" | indentree
```
Output:
diff --git a/cmd/mp4dump/main.go b/cmd/mfdump/main.go
index ee7a577..42f4bf1 100644
--- a/cmd/mp4dump/main.go
+++ b/cmd/mfdump/main.go
@@ -1,4 +1,4 @@
-// Command mp4dump reads an MP4 file and prints its box structure.
+// Command mfdump reads a media file and prints its box structure.
package main
import (
@@ -6,7 +6,7 @@ import (
"os"
"strings"
- "github.com/tetsuo/mp4"
+ mf "github.com/tetsuo/isobmff"
)
func main() {
@@ -22,27 +22,27 @@ func main() {
}
defer f.Close()
- sc := mp4.NewScanner(f)
+ sc := mf.NewScanner(f)
for sc.Next() {
e := sc.Entry()
fmt.Printf("[%s] size=%d\n", e.Type, e.Size)
// Only load metadata boxes into memory for deep parsing
- if e.Type == mp4.TypeMoov || e.Type == mp4.TypeMoof {
+ if e.Type == mf.TypeMoov || e.Type == mf.TypeMoof {
buf := make([]byte, e.DataSize())
if err := sc.ReadBody(buf); err != nil {
fmt.Fprintf(os.Stderr, "error reading %s: %v\n", e.Type, err)
continue
}
- r := mp4.NewReader(buf)
+ r := mf.NewReader(buf)
walk(&r, 1)
- } else if e.Type == mp4.TypeFtyp {
+ } else if e.Type == mf.TypeFtyp {
buf := make([]byte, e.DataSize())
if err := sc.ReadBody(buf); err != nil {
fmt.Fprintf(os.Stderr, "error reading ftyp: %v\n", err)
continue
}
- f := mp4.ReadFtyp(buf)
+ f := mf.ReadFtyp(buf)
fmt.Printf(" brand=%s ver=%d", string(f.MajorBrand[:]), f.MinorVersion)
if len(f.Compatible) > 0 {
fmt.Printf(" compat=[")
@@ -55,7 +55,7 @@ func main() {
fmt.Printf("]")
}
fmt.Println()
- } else if e.Type == mp4.TypeMdat {
+ } else if e.Type == mf.TypeMdat {
fmt.Printf(" dataLen=%d\n", e.DataSize())
}
}
@@ -65,13 +65,13 @@ func main() {
}
}
-func walk(r *mp4.Reader, depth int) {
+func walk(r *mf.Reader, depth int) {
for r.Next() {
indent := strings.Repeat(" ", depth)
fmt.Printf("%s[%s] size=%d", indent, r.Type(), r.Size())
- if mp4.IsFullBox(r.Type()) {
+ if mf.IsFullBox(r.Type()) {
fmt.Printf(" v=%d flags=0x%06x", r.Version(), r.Flags())
}
@@ -79,7 +79,7 @@ func walk(r *mp4.Reader, depth int) {
fmt.Println()
// Descend into containers
- if mp4.IsContainerBox(r.Type()) {
+ if mf.IsContainerBox(r.Type()) {
r.Enter()
walk(r, depth+1)
r.Exit()
@@ -87,7 +87,7 @@ func walk(r *mp4.Reader, depth int) {
}
// Handle stsd: entry count + sub-boxes
- if r.Type() == mp4.TypeStsd {
+ if r.Type() == mf.TypeStsd {
r.Enter()
r.Skip(4) // skip entry count
for r.Next() {
@@ -99,46 +99,46 @@ func walk(r *mp4.Reader, depth int) {
}
}
-func printSampleEntry(r *mp4.Reader, depth int) {
+func printSampleEntry(r *mf.Reader, depth int) {
indent := strings.Repeat(" ", depth)
switch r.Type() {
- case mp4.TypeAvc1:
- v := mp4.ReadVisualSampleEntry(r.Data())
+ case mf.TypeAvc1:
+ v := mf.ReadVisualSampleEntry(r.Data())
fmt.Printf("%s[%s] size=%d %dx%d compressor=%q\n", indent, r.Type(), r.Size(), v.Width, v.Height, v.CompressorName)
// Enter to find avcC and other children
r.Enter()
r.Skip(v.ChildOffset)
for r.Next() {
childIndent := strings.Repeat(" ", depth+1)
- if mp4.IsFullBox(r.Type()) {
+ if mf.IsFullBox(r.Type()) {
fmt.Printf("%s[%s] size=%d v=%d flags=0x%06x", childIndent, r.Type(), r.Size(), r.Version(), r.Flags())
} else {
fmt.Printf("%s[%s] size=%d", childIndent, r.Type(), r.Size())
}
- if r.Type() == mp4.TypeAvcC {
- codec := mp4.ReadAvcC(r.Data())
+ if r.Type() == mf.TypeAvcC {
+ codec := mf.ReadAvcC(r.Data())
fmt.Printf(" codec=%s", codec)
}
fmt.Println()
}
r.Exit()
- case mp4.TypeMp4a:
- a := mp4.ReadAudioSampleEntry(r.Data())
+ case mf.TypeMp4a:
+ a := mf.ReadAudioSampleEntry(r.Data())
fmt.Printf("%s[%s] size=%d ch=%d sampleSize=%d sampleRate=%d\n", indent, r.Type(), r.Size(), a.ChannelCount, a.SampleSize, a.SampleRate>>16)
// Enter to find esds and other children
r.Enter()
r.Skip(a.ChildOffset)
for r.Next() {
childIndent := strings.Repeat(" ", depth+1)
- if mp4.IsFullBox(r.Type()) {
+ if mf.IsFullBox(r.Type()) {
fmt.Printf("%s[%s] size=%d v=%d flags=0x%06x", childIndent, r.Type(), r.Size(), r.Version(), r.Flags())
} else {
fmt.Printf("%s[%s] size=%d", childIndent, r.Type(), r.Size())
}
- if r.Type() == mp4.TypeEsds {
- codec := mp4.ReadEsdsCodec(r.Data())
+ if r.Type() == mf.TypeEsds {
+ codec := mf.ReadEsdsCodec(r.Data())
fmt.Printf(" codec=%s", codec)
}
fmt.Println()
@@ -147,17 +147,17 @@ func printSampleEntry(r *mp4.Reader, depth int) {
default:
fmt.Printf("%s[%s] size=%d", indent, r.Type(), r.Size())
- if mp4.IsFullBox(r.Type()) {
+ if mf.IsFullBox(r.Type()) {
fmt.Printf(" v=%d flags=0x%06x", r.Version(), r.Flags())
}
fmt.Printf(" (raw %d bytes)\n", len(r.Data()))
}
}
-func printBoxInfo(r *mp4.Reader) {
+func printBoxInfo(r *mf.Reader) {
switch r.Type() {
- case mp4.TypeFtyp:
- f := mp4.ReadFtyp(r.Data())
+ case mf.TypeFtyp:
+ f := mf.ReadFtyp(r.Data())
fmt.Printf(" brand=%s ver=%d", string(f.MajorBrand[:]), f.MinorVersion)
if len(f.Compatible) > 0 {
fmt.Printf(" compat=[")
@@ -170,97 +170,97 @@ func printBoxInfo(r *mp4.Reader) {
fmt.Printf("]")
}
- case mp4.TypeMvhd:
+ case mf.TypeMvhd:
ts, dur, ntid := r.ReadMvhd()
fmt.Printf(" timescale=%d duration=%d nextTrackId=%d", ts, dur, ntid)
- case mp4.TypeTkhd:
+ case mf.TypeTkhd:
tid, dur, w, h := r.ReadTkhd()
fmt.Printf(" trackId=%d duration=%d size=%dx%d", tid, dur, w>>16, h>>16)
- case mp4.TypeMdhd:
+ case mf.TypeMdhd:
ts, dur, lang := r.ReadMdhd()
fmt.Printf(" timescale=%d duration=%d lang=%d", ts, dur, lang)
- case mp4.TypeHdlr:
+ case mf.TypeHdlr:
ht := r.ReadHdlr()
name := r.ReadHdlrName()
fmt.Printf(" type=%s name=%q", string(ht[:]), name)
- case mp4.TypeStsd:
+ case mf.TypeStsd:
if len(r.Data()) >= 4 {
fmt.Printf(" entries=%d", r.EntryCount())
}
- case mp4.TypeStsz:
- it := mp4.NewStszIter(r.Data())
+ case mf.TypeStsz:
+ it := mf.NewStszIter(r.Data())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeStco, mp4.TypeStss:
- it := mp4.NewUint32Iter(r.Data())
+ case mf.TypeStco, mf.TypeStss:
+ it := mf.NewUint32Iter(r.Data())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeCo64:
- it := mp4.NewCo64Iter(r.Data())
+ case mf.TypeCo64:
+ it := mf.NewCo64Iter(r.Data())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeStts:
- it := mp4.NewSttsIter(r.Data())
+ case mf.TypeStts:
+ it := mf.NewSttsIter(r.Data())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeCtts:
- it := mp4.NewCttsIter(r.Data(), r.Version())
+ case mf.TypeCtts:
+ it := mf.NewCttsIter(r.Data(), r.Version())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeStsc:
- it := mp4.NewStscIter(r.Data())
+ case mf.TypeStsc:
+ it := mf.NewStscIter(r.Data())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeElst:
- it := mp4.NewElstIter(r.Data(), r.Version())
+ case mf.TypeElst:
+ it := mf.NewElstIter(r.Data(), r.Version())
fmt.Printf(" entries=%d", it.Count())
- case mp4.TypeDref:
+ case mf.TypeDref:
if len(r.Data()) >= 4 {
fmt.Printf(" entries=%d", r.EntryCount())
}
- case mp4.TypeMehd:
+ case mf.TypeMehd:
dur := r.ReadMehd()
fmt.Printf(" fragmentDuration=%d", dur)
- case mp4.TypeTrex:
+ case mf.TypeTrex:
tid, _, _, _, _ := r.ReadTrex()
fmt.Printf(" trackId=%d", tid)
- case mp4.TypeMfhd:
+ case mf.TypeMfhd:
seq := r.ReadMfhd()
fmt.Printf(" seq=%d", seq)
- case mp4.TypeTfhd:
+ case mf.TypeTfhd:
tid := r.ReadTfhd()
fmt.Printf(" trackId=%d", tid)
- case mp4.TypeTfdt:
+ case mf.TypeTfdt:
bt := r.ReadTfdt()
fmt.Printf(" baseMediaDecodeTime=%d", bt)
- case mp4.TypeTrun:
- it := mp4.NewTrunIter(r.Data(), r.Flags())
+ case mf.TypeTrun:
+ it := mf.NewTrunIter(r.Data(), r.Flags())
fmt.Printf(" entries=%d", it.Count())
- if r.Flags()&mp4.TrunDataOffsetPresent != 0 {
+ if r.Flags()&mf.TrunDataOffsetPresent != 0 {
fmt.Printf(" dataOffset=%d", it.DataOffset())
}
- case mp4.TypeMdat:
+ case mf.TypeMdat:
fmt.Printf(" dataLen=%d", len(r.Data()))
- case mp4.TypeVmhd:
+ case mf.TypeVmhd:
// graphicsMode and opcolor
- case mp4.TypeSmhd:
+ case mf.TypeSmhd:
// balance
default:
- if !mp4.IsContainerBox(r.Type()) {
+ if !mf.IsContainerBox(r.Type()) {
if len(r.Data()) > 0 {
fmt.Printf(" (%d bytes)", len(r.Data()))
}
diff --git a/descriptor.go b/descriptor.go
index 746bec1..8b0a1fb 100644
--- a/descriptor.go
+++ b/descriptor.go
@@ -1,4 +1,4 @@
-package mp4
+package isobmff
import "strconv"
diff --git a/go.mod b/go.mod
index 4b0b7a2..8cf4047 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
-module github.com/tetsuo/mp4
+module github.com/tetsuo/isobmff
go 1.25.5
diff --git a/iter.go b/iter.go
index 2ec0e1f..2ae1117 100644
--- a/iter.go
+++ b/iter.go
@@ -1,4 +1,4 @@
-package mp4
+package isobmff
import (
"encoding/binary"
diff --git a/reader.go b/reader.go
index f9531b5..b2b9a00 100644
--- a/reader.go
+++ b/reader.go
@@ -1,4 +1,4 @@
-package mp4
+package isobmff
// maxDepth limits the reader/writer nesting stack.
const maxDepth = 16
@@ -9,7 +9,7 @@ type readerFrame struct {
boxEnd int // position to resume after exiting this container
}
-// Reader provides streaming parsing of MP4 boxes.
+// Reader provides streaming parsing of ISOBMFF boxes.
type Reader struct {
buf []byte
pos int // next position to parse from
diff --git a/scanner.go b/scanner.go
index 4466dc7..f1ce72b 100644
--- a/scanner.go
+++ b/scanner.go
@@ -1,4 +1,4 @@
-package mp4
+package isobmff
import "io"
@@ -23,13 +23,13 @@ func (e ScanEntry) DataSize() int64 {
// Typical usage:
//
// f, _ := os.Open("video.mp4")
-// sc := mp4.NewScanner(f)
+// sc := isobmff.NewScanner(f)
// for sc.Next() {
// e := sc.Entry()
-// if e.Type == mp4.TypeMoov {
+// if e.Type == isobmff.TypeMoov {
// buf := make([]byte, e.DataSize())
// sc.ReadBody(buf)
-// r := mp4.NewReader(buf)
+// r := isobmff.NewReader(buf)
// // parse moov contents...
// }
// }
diff --git a/writer.go b/writer.go
index c7a1b28..f21e3c6 100644
--- a/writer.go
+++ b/writer.go
@@ -1,11 +1,11 @@
-package mp4
+package isobmff
// writerFrame tracks the start offset of a box for size backpatching.
type writerFrame struct {
offset int
}
-// Writer builds MP4 data into a caller-provided fixed-size byte buffer.
+// Writer encodes ISOBMFF boxes into a byte buffer.
type Writer struct {
buf []byte
pos int
@@ -443,10 +443,7 @@ func (w *Writer) WriteVisualSampleEntry(dataRefIdx, width, height, frameCount, d
w.putUint32(0x00480000) // vresolution 72 dpi
w.putZeros(4) // reserved
w.putUint16(frameCount) // frame count
- nameLen := len(compressor)
- if nameLen > 31 {
- nameLen = 31
- }
+ nameLen := min(len(compressor), 31)
w.putUint8(byte(nameLen))
w.putFixedString(compressor, 31)
w.putUint16(depth) // depth