@@ -12,6 +12,20 @@ import (
12
12
"github.com/ebml-go/ebml"
13
13
)
14
14
15
+ type TrackType uint8 // ffmpeg define this in 8 bits(uint8 in Go)
16
+
17
+ const (
18
+ TrackTypeNone TrackType = 0x0
19
+ TrackTypeVideo TrackType = 0x1
20
+ TrackTypeAudio TrackType = 0x2
21
+ TrackTypeComplex TrackType = 0x3
22
+ TrackTypeLogo TrackType = 0x10
23
+ TrackTypeSubtitle TrackType = 0x11
24
+ TrackTypeButtons TrackType = 0x12
25
+ TrackTypeControl TrackType = 0x20
26
+ TrackTypeMetadata TrackType = 0x21
27
+ )
28
+
15
29
type WebM struct {
16
30
Header `ebml:"1a45dfa3"`
17
31
Segment `ebml:"18538067"`
@@ -82,11 +96,15 @@ func (t *TrackEntry) GetDefaultDuration() time.Duration {
82
96
}
83
97
84
98
func (t * TrackEntry ) IsVideo () bool {
85
- return t .TrackType == 1
99
+ return TrackType ( t .TrackType ) == TrackTypeVideo
86
100
}
87
101
88
102
func (t * TrackEntry ) IsAudio () bool {
89
- return t .TrackType == 2
103
+ return TrackType (t .TrackType ) == TrackTypeAudio
104
+ }
105
+
106
+ func (t * TrackEntry ) IsSubtitle () bool {
107
+ return TrackType (t .TrackType ) == TrackTypeSubtitle
90
108
}
91
109
92
110
type Video struct {
@@ -128,11 +146,18 @@ type SegmentInformation struct {
128
146
WritingApp string `ebml:"5741"`
129
147
}
130
148
149
+ // return duration in seconds
131
150
func (s * SegmentInformation ) GetDuration () time.Duration {
132
151
return time .Second * time .Duration (
133
152
s .Duration * float64 (s .TimecodeScale )/ 1000000000 )
134
153
}
135
154
155
+ // return duration in milliseconds
156
+ func (s * SegmentInformation ) GetDurationMs () time.Duration {
157
+ return time .Millisecond * time .Duration (
158
+ s .Duration * float64 (s .TimecodeScale )/ 1000000 )
159
+ }
160
+
136
161
type Cluster struct {
137
162
simpleBlock []byte `ebml:"A3" ebmlstop:"1"`
138
163
Timecode uint `ebml:"E7"`
@@ -178,8 +203,8 @@ func Parse(r io.ReadSeeker, m *WebM) (wr *Reader, err error) {
178
203
if err == nil {
179
204
err = e .Unmarshal (m )
180
205
dt := m .Header .DocType
181
- if dt != "webm" && dt != "webm\000 " {
182
- err = errors .New ("Not a WebM file" )
206
+ if dt != "webm" && dt != "webm\000 " && dt != "matroska" {
207
+ err = errors .New ("Not a WebM or matroska file" )
183
208
}
184
209
if err != nil && err .Error () == "Reached payload" {
185
210
segment := err .(ebml.ReachedPayloadError ).Element
0 commit comments