-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoov.go
69 lines (63 loc) · 1.47 KB
/
moov.go
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
package bmff
import (
"fmt"
)
// The Movie Box is short-formed as the type 'moov'.
// The metadata for a presentation is stored in the single Movie Box which occurs at the top‐level of a file.
// Normally this box is close to the beginning or end of the file, though this is not required.
type Movie struct {
*box
Header *MovieHeader
Tracks []*TrakBox
Iods *IodsBox
Metadata *Metadata
UserData *UserData
Unknown []*box
}
func (b *Movie) parse() error {
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "mvhd", "iods", "meta":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "mvhd":
b.Header = &MovieHeader{fullbox: fb}
if err := b.Header.parse(); err != nil {
return err
}
case "iods":
b.Iods = &IodsBox{fullbox: fb}
if err := b.Iods.parse(); err != nil {
return err
}
case "trak":
trak := &TrakBox{box: subBox}
if err := trak.parse(); err != nil {
return err
}
b.Tracks = append(b.Tracks, trak)
case "udta":
udta := &UserData{box: subBox}
if err := udta.parse(); err != nil {
return err
}
b.UserData = udta
case "meta":
meta := &Metadata{fullbox: fb}
if err := meta.parse(); err != nil {
return err
}
b.Metadata = meta
default:
b.Unknown = append(b.Unknown, subBox)
fmt.Printf("unknown '%s' child: %s\n", b.boxtype, subBox.Type())
}
}
b.raw = nil
return nil
}