aboutsummaryrefslogtreecommitdiff
path: root/cmd/mp4probe/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/mp4probe/main.go')
-rw-r--r--cmd/mp4probe/main.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/cmd/mp4probe/main.go b/cmd/mp4probe/main.go
new file mode 100644
index 0000000..3681a1d
--- /dev/null
+++ b/cmd/mp4probe/main.go
@@ -0,0 +1,97 @@
+// Command mp4probe displays information about MP4 tracks and keyframes.
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+
+ "github.com/tetsuo/mp4/fragment"
+ "github.com/tetsuo/mp4/track"
+)
+
+func main() {
+ if len(os.Args) < 2 {
+ fmt.Fprintf(os.Stderr, "usage: %s <file.mp4>\n", os.Args[0])
+ os.Exit(1)
+ }
+
+ f, err := os.Open(os.Args[1])
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
+ os.Exit(1)
+ }
+ defer f.Close()
+
+ fr, initSeg, err := fragment.NewReader(f)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Printf("Tracks: %d\n", len(initSeg.Tracks))
+ for _, t := range initSeg.Tracks {
+ kind := "video"
+ if t.Kind == track.TrackAudio {
+ kind = "audio"
+ }
+ fmt.Printf("\n%s Track (ID=%d):\n", kind, t.ID)
+ fmt.Printf(" Codec: %s\n", t.Codec())
+ fmt.Printf(" Timescale: %d\n", t.TimeScale)
+ seconds := 0.0
+ if t.TimeScale > 0 {
+ seconds = float64(t.Duration) / float64(t.TimeScale)
+ }
+ fmt.Printf(" Duration: %d ticks (%.2fs)\n", t.Duration, seconds)
+
+ if t.Kind == track.TrackVideo {
+ fmt.Printf(" Resolution: %dx%d\n", t.Width, t.Height)
+ } else {
+ fmt.Printf(" Channels: %d\n", t.ChannelCount)
+ fmt.Printf(" Sample Rate: %d\n", t.SampleRate)
+ }
+ }
+
+ // Read and analyze fragments
+ fmt.Printf("\nFragments:\n")
+ fragCount := 0
+ totalSamples := 0
+ totalVideoSync := 0
+
+ for {
+ fr, err := fr.ReadFragment()
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
+ os.Exit(1)
+ }
+
+ videoSamples := 0
+ audioSamples := 0
+ syncSamples := 0
+
+ for _, s := range fr.Samples {
+ t := track.FindTrack(initSeg.Tracks, s.TrackID)
+ if t != nil && t.Kind == track.TrackVideo {
+ videoSamples++
+ if s.IsSync() {
+ syncSamples++
+ }
+ } else {
+ audioSamples++
+ }
+ }
+
+ fmt.Printf(" Fragment %d: %d video (%d sync), %d audio\n",
+ fr.SequenceNum, videoSamples, syncSamples, audioSamples)
+
+ fragCount++
+ totalSamples += len(fr.Samples)
+ totalVideoSync += syncSamples
+ }
+
+ fmt.Printf("\nSummary: %d fragments, %d samples, %d video keyframes\n",
+ fragCount, totalSamples, totalVideoSync)
+}