diff options
Diffstat (limited to 'cmd')
| -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 |
2 files changed, 63 insertions, 63 deletions
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())) } |
