-
Notifications
You must be signed in to change notification settings - Fork 7
/
Header.go
73 lines (62 loc) · 2.32 KB
/
Header.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
70
71
72
73
package format
import (
"fmt"
"math"
)
// Tag is the identifier key of a MOVI container.
const Tag string = "MOVI"
// HeaderSize specifies the length of a serialized Header in bytes.
const HeaderSize = 256
// Fix represents a fixed-point number, with 16 bits of fraction and 15 bits of integer number.
type Fix struct {
Fraction uint16
Number int16
}
// FixFromFloat returns a fixed-point number from given floating-point number.
func FixFromFloat(value float32) Fix {
number := int16(value)
return Fix{
Fraction: uint16(math.Abs(float64(value)-float64(number)) * 0x10000),
Number: number,
}
}
// ToFloat returns the equivalent floating-point number.
func (f Fix) ToFloat() float32 {
return float32(f.Number) + float32(f.Fraction)/0x10000
}
// Header is the first entry of a MOVI container.
type Header struct {
// Tag is the identifier key of a MOVI container
Tag [4]byte
// IndexEntryCount specifies how many index entries are in the index.
IndexEntryCount int32
// IndexSize specifies how long the index is.
IndexSize int32
// ContentSize specifies the length of the content.
ContentSize int32
// Duration is the length of the media in seconds.
Duration Fix
// VideoFrameRate gives a hint on number of frames per second.
VideoFrameRate Fix
// VideoWidth specifies the width of the video.
VideoWidth uint16
// VideoHeight specifies the height of the video.
VideoHeight uint16
// VideoBitsPerPixel specifies bit count for color information: 8, 15, 24.
VideoBitsPerPixel int16
// VideoPalettePresent specifies whether a palette is set.
VideoPalettePresent int16
// AudioChannelCount specifies whether there is audio, and how many channels to use. 0 = no audio, 1 = mono, 2 = stereo.
AudioChannelCount int16
// AudioBytesPerSample specifies how many bytes one audio sample has. 1 = 8-bit, 2 = 16-bit.
AudioBytesPerSample int16
// AudioSampleRate specifies the sample rate of the audio.
AudioSampleRate Fix
_ [216]byte
}
func (header *Header) String() (result string) {
result += fmt.Sprintf("Index: %d entries (%d bytes)\n", header.IndexEntryCount, header.IndexSize)
result += fmt.Sprintf("Content: %d bytes, %f seconds\n", header.ContentSize, header.Duration.ToFloat())
result += fmt.Sprintf("Video: %dx%d pixel @%f sample rate\n", header.VideoWidth, header.VideoHeight, header.AudioSampleRate.ToFloat())
return
}