forked from mstoykov/mp4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmhd.go
58 lines (52 loc) · 1.13 KB
/
vmhd.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
package mp4
import (
"encoding/binary"
"io"
)
// Video Media Header Box (vhmd - mandatory for video tracks)
//
// Contained in : Media Information Box (minf)
//
// Status: decoded
type VmhdBox struct {
Version byte
Flags [3]byte
GraphicsMode uint16
OpColor [3]uint16
}
func DecodeVmhd(r io.Reader, size uint64) (Box, error) {
data, err := read(r, size)
if err != nil {
return nil, err
}
b := &VmhdBox{
Version: data[0],
Flags: [3]byte{data[1], data[2], data[3]},
GraphicsMode: binary.BigEndian.Uint16(data[4:6]),
}
for i := 0; i < 3; i++ {
b.OpColor[i] = binary.BigEndian.Uint16(data[(6 + 2*i):(8 + 2*i)])
}
return b, nil
}
func (b *VmhdBox) Type() string {
return "vmhd"
}
func (b *VmhdBox) Size() uint64 {
return 12
}
func (b *VmhdBox) Encode(w io.Writer) error {
err := EncodeHeader(b, w)
if err != nil {
return err
}
buf := makebuf(b)
buf[0] = b.Version
buf[1], buf[2], buf[3] = b.Flags[0], b.Flags[1], b.Flags[2]
binary.BigEndian.PutUint16(buf[4:], b.GraphicsMode)
for i := 0; i < 3; i++ {
binary.BigEndian.PutUint16(buf[6+2*i:], b.OpColor[i])
}
_, err = w.Write(buf)
return err
}