1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Command mp4probe displays information about MP4 tracks and keyframes.
package main
import (
"fmt"
"io"
"os"
"git.onurgunduz.com/mp4/fragment"
"git.onurgunduz.com/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)
}
|