-
Notifications
You must be signed in to change notification settings - Fork 31
/
box_types_iso14496_12.go
2460 lines (2034 loc) · 62.1 KB
/
box_types_iso14496_12.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package mp4
import (
"errors"
"fmt"
"io"
"github.com/abema/go-mp4/internal/bitio"
"github.com/abema/go-mp4/internal/util"
)
/*************************** btrt ****************************/
func BoxTypeBtrt() BoxType { return StrToBoxType("btrt") }
func init() {
AddBoxDef(&Btrt{}, 0)
}
type Btrt struct {
Box
BufferSizeDB uint32 `mp4:"0,size=32"`
MaxBitrate uint32 `mp4:"1,size=32"`
AvgBitrate uint32 `mp4:"2,size=32"`
}
// GetType returns the BoxType
func (*Btrt) GetType() BoxType {
return BoxTypeBtrt()
}
/*************************** co64 ****************************/
func BoxTypeCo64() BoxType { return StrToBoxType("co64") }
func init() {
AddBoxDef(&Co64{}, 0)
}
type Co64 struct {
FullBox `mp4:"0,extend"`
EntryCount uint32 `mp4:"1,size=32"`
ChunkOffset []uint64 `mp4:"2,size=64,len=dynamic"`
}
// GetType returns the BoxType
func (*Co64) GetType() BoxType {
return BoxTypeCo64()
}
// GetFieldLength returns length of dynamic field
func (co64 *Co64) GetFieldLength(name string, ctx Context) uint {
switch name {
case "ChunkOffset":
return uint(co64.EntryCount)
}
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=co64 fieldName=%s", name))
}
/*************************** colr ****************************/
func BoxTypeColr() BoxType { return StrToBoxType("colr") }
func init() {
AddBoxDef(&Colr{})
}
type Colr struct {
Box
ColourType [4]byte `mp4:"0,size=8,string"`
ColourPrimaries uint16 `mp4:"1,size=16,opt=dynamic"`
TransferCharacteristics uint16 `mp4:"2,size=16,opt=dynamic"`
MatrixCoefficients uint16 `mp4:"3,size=16,opt=dynamic"`
FullRangeFlag bool `mp4:"4,size=1,opt=dynamic"`
Reserved uint8 `mp4:"5,size=7,opt=dynamic"`
Profile []byte `mp4:"6,size=8,opt=dynamic"`
Unknown []byte `mp4:"7,size=8,opt=dynamic"`
}
func (colr *Colr) IsOptFieldEnabled(name string, ctx Context) bool {
switch colr.ColourType {
case [4]byte{'n', 'c', 'l', 'x'}:
switch name {
case "ColourType",
"ColourPrimaries",
"TransferCharacteristics",
"MatrixCoefficients",
"FullRangeFlag",
"Reserved":
return true
default:
return false
}
case [4]byte{'r', 'I', 'C', 'C'}, [4]byte{'p', 'r', 'o', 'f'}:
return name == "Profile"
default:
return name == "Unknown"
}
}
// GetType returns the BoxType
func (*Colr) GetType() BoxType {
return BoxTypeColr()
}
/*************************** cslg ****************************/
func BoxTypeCslg() BoxType { return StrToBoxType("cslg") }
func init() {
AddBoxDef(&Cslg{}, 0, 1)
}
type Cslg struct {
FullBox `mp4:"0,extend"`
CompositionToDTSShiftV0 int32 `mp4:"1,size=32,ver=0"`
LeastDecodeToDisplayDeltaV0 int32 `mp4:"2,size=32,ver=0"`
GreatestDecodeToDisplayDeltaV0 int32 `mp4:"3,size=32,ver=0"`
CompositionStartTimeV0 int32 `mp4:"4,size=32,ver=0"`
CompositionEndTimeV0 int32 `mp4:"5,size=32,ver=0"`
CompositionToDTSShiftV1 int64 `mp4:"6,size=64,nver=0"`
LeastDecodeToDisplayDeltaV1 int64 `mp4:"7,size=64,nver=0"`
GreatestDecodeToDisplayDeltaV1 int64 `mp4:"8,size=64,nver=0"`
CompositionStartTimeV1 int64 `mp4:"9,size=64,nver=0"`
CompositionEndTimeV1 int64 `mp4:"10,size=64,nver=0"`
}
// GetType returns the BoxType
func (*Cslg) GetType() BoxType {
return BoxTypeCslg()
}
func (cslg *Cslg) GetCompositionToDTSShift() int64 {
switch cslg.GetVersion() {
case 0:
return int64(cslg.CompositionToDTSShiftV0)
case 1:
return cslg.CompositionToDTSShiftV1
default:
return 0
}
}
func (cslg *Cslg) GetLeastDecodeToDisplayDelta() int64 {
switch cslg.GetVersion() {
case 0:
return int64(cslg.LeastDecodeToDisplayDeltaV0)
case 1:
return cslg.LeastDecodeToDisplayDeltaV1
default:
return 0
}
}
func (cslg *Cslg) GetGreatestDecodeToDisplayDelta() int64 {
switch cslg.GetVersion() {
case 0:
return int64(cslg.GreatestDecodeToDisplayDeltaV0)
case 1:
return cslg.GreatestDecodeToDisplayDeltaV1
default:
return 0
}
}
func (cslg *Cslg) GetCompositionStartTime() int64 {
switch cslg.GetVersion() {
case 0:
return int64(cslg.CompositionStartTimeV0)
case 1:
return cslg.CompositionStartTimeV1
default:
return 0
}
}
func (cslg *Cslg) GetCompositionEndTime() int64 {
switch cslg.GetVersion() {
case 0:
return int64(cslg.CompositionEndTimeV0)
case 1:
return cslg.CompositionEndTimeV1
default:
return 0
}
}
/*************************** ctts ****************************/
func BoxTypeCtts() BoxType { return StrToBoxType("ctts") }
func init() {
AddBoxDef(&Ctts{}, 0, 1)
}
type Ctts struct {
FullBox `mp4:"0,extend"`
EntryCount uint32 `mp4:"1,size=32"`
Entries []CttsEntry `mp4:"2,len=dynamic,size=64"`
}
type CttsEntry struct {
SampleCount uint32 `mp4:"0,size=32"`
SampleOffsetV0 uint32 `mp4:"1,size=32,ver=0"`
SampleOffsetV1 int32 `mp4:"2,size=32,ver=1"`
}
// GetType returns the BoxType
func (*Ctts) GetType() BoxType {
return BoxTypeCtts()
}
// GetFieldLength returns length of dynamic field
func (ctts *Ctts) GetFieldLength(name string, ctx Context) uint {
switch name {
case "Entries":
return uint(ctts.EntryCount)
}
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=ctts fieldName=%s", name))
}
func (ctts *Ctts) GetSampleOffset(index int) int64 {
switch ctts.GetVersion() {
case 0:
return int64(ctts.Entries[index].SampleOffsetV0)
case 1:
return int64(ctts.Entries[index].SampleOffsetV1)
default:
return 0
}
}
/*************************** dinf ****************************/
func BoxTypeDinf() BoxType { return StrToBoxType("dinf") }
func init() {
AddBoxDef(&Dinf{})
}
// Dinf is ISOBMFF dinf box type
type Dinf struct {
Box
}
// GetType returns the BoxType
func (*Dinf) GetType() BoxType {
return BoxTypeDinf()
}
/*************************** dref ****************************/
func BoxTypeDref() BoxType { return StrToBoxType("dref") }
func BoxTypeUrl() BoxType { return StrToBoxType("url ") }
func BoxTypeUrn() BoxType { return StrToBoxType("urn ") }
func init() {
AddBoxDef(&Dref{}, 0)
AddBoxDef(&Url{}, 0)
AddBoxDef(&Urn{}, 0)
}
// Dref is ISOBMFF dref box type
type Dref struct {
FullBox `mp4:"0,extend"`
EntryCount uint32 `mp4:"1,size=32"`
}
// GetType returns the BoxType
func (*Dref) GetType() BoxType {
return BoxTypeDref()
}
type Url struct {
FullBox `mp4:"0,extend"`
Location string `mp4:"1,string,nopt=0x000001"`
}
func (*Url) GetType() BoxType {
return BoxTypeUrl()
}
const UrlSelfContained = 0x000001
type Urn struct {
FullBox `mp4:"0,extend"`
Name string `mp4:"1,string,nopt=0x000001"`
Location string `mp4:"2,string,nopt=0x000001"`
}
func (*Urn) GetType() BoxType {
return BoxTypeUrn()
}
const UrnSelfContained = 0x000001
/*************************** edts ****************************/
func BoxTypeEdts() BoxType { return StrToBoxType("edts") }
func init() {
AddBoxDef(&Edts{})
}
// Edts is ISOBMFF edts box type
type Edts struct {
Box
}
// GetType returns the BoxType
func (*Edts) GetType() BoxType {
return BoxTypeEdts()
}
/*************************** elst ****************************/
func BoxTypeElst() BoxType { return StrToBoxType("elst") }
func init() {
AddBoxDef(&Elst{}, 0, 1)
}
// Elst is ISOBMFF elst box type
type Elst struct {
FullBox `mp4:"0,extend"`
EntryCount uint32 `mp4:"1,size=32"`
Entries []ElstEntry `mp4:"2,len=dynamic,size=dynamic"`
}
type ElstEntry struct {
SegmentDurationV0 uint32 `mp4:"0,size=32,ver=0"`
MediaTimeV0 int32 `mp4:"1,size=32,ver=0"`
SegmentDurationV1 uint64 `mp4:"2,size=64,ver=1"`
MediaTimeV1 int64 `mp4:"3,size=64,ver=1"`
MediaRateInteger int16 `mp4:"4,size=16"`
MediaRateFraction int16 `mp4:"5,size=16,const=0"`
}
// GetType returns the BoxType
func (*Elst) GetType() BoxType {
return BoxTypeElst()
}
// GetFieldSize returns size of dynamic field
func (elst *Elst) GetFieldSize(name string, ctx Context) uint {
switch name {
case "Entries":
switch elst.GetVersion() {
case 0:
return 0 +
/* segmentDurationV0 */ 32 +
/* mediaTimeV0 */ 32 +
/* mediaRateInteger */ 16 +
/* mediaRateFraction */ 16
case 1:
return 0 +
/* segmentDurationV1 */ 64 +
/* mediaTimeV1 */ 64 +
/* mediaRateInteger */ 16 +
/* mediaRateFraction */ 16
}
}
panic(fmt.Errorf("invalid name of dynamic-size field: boxType=elst fieldName=%s", name))
}
// GetFieldLength returns length of dynamic field
func (elst *Elst) GetFieldLength(name string, ctx Context) uint {
switch name {
case "Entries":
return uint(elst.EntryCount)
}
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=elst fieldName=%s", name))
}
func (elst *Elst) GetSegmentDuration(index int) uint64 {
switch elst.GetVersion() {
case 0:
return uint64(elst.Entries[index].SegmentDurationV0)
case 1:
return elst.Entries[index].SegmentDurationV1
default:
return 0
}
}
func (elst *Elst) GetMediaTime(index int) int64 {
switch elst.GetVersion() {
case 0:
return int64(elst.Entries[index].MediaTimeV0)
case 1:
return elst.Entries[index].MediaTimeV1
default:
return 0
}
}
/*************************** emsg ****************************/
func BoxTypeEmsg() BoxType { return StrToBoxType("emsg") }
func init() {
AddBoxDef(&Emsg{}, 0, 1)
}
// Emsg is ISOBMFF emsg box type
type Emsg struct {
FullBox `mp4:"0,extend"`
SchemeIdUri string `mp4:"1,string"`
Value string `mp4:"2,string"`
Timescale uint32 `mp4:"3,size=32"`
PresentationTimeDelta uint32 `mp4:"4,size=32,ver=0"`
PresentationTime uint64 `mp4:"5,size=64,ver=1"`
EventDuration uint32 `mp4:"6,size=32"`
Id uint32 `mp4:"7,size=32"`
MessageData []byte `mp4:"8,size=8,string"`
}
func (emsg *Emsg) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, ctx Context) (rbits uint64, override bool, err error) {
if emsg.GetVersion() == 0 {
return
}
switch name {
case "SchemeIdUri", "Value":
override = true
return
case "MessageData":
emsg.SchemeIdUri, err = util.ReadString(r)
if err != nil {
return
}
emsg.Value, err = util.ReadString(r)
if err != nil {
return
}
rbits += uint64(len(emsg.SchemeIdUri)+len(emsg.Value)+2) * 8
return
default:
return
}
}
func (emsg *Emsg) OnWriteField(name string, w bitio.Writer, ctx Context) (wbits uint64, override bool, err error) {
if emsg.GetVersion() == 0 {
return
}
switch name {
case "SchemeIdUri", "Value":
override = true
return
case "MessageData":
if err = util.WriteString(w, emsg.SchemeIdUri); err != nil {
return
}
if err = util.WriteString(w, emsg.Value); err != nil {
return
}
wbits += uint64(len(emsg.SchemeIdUri)+len(emsg.Value)+2) * 8
return
default:
return
}
}
// GetType returns the BoxType
func (*Emsg) GetType() BoxType {
return BoxTypeEmsg()
}
/*************************** fiel ****************************/
func BoxTypeFiel() BoxType { return StrToBoxType("fiel") }
func init() {
AddBoxDef(&Fiel{})
}
type Fiel struct {
Box
FieldCount uint8 `mp4:"0,size=8"`
FieldOrdering uint8 `mp4:"1,size=8"`
}
func (Fiel) GetType() BoxType {
return BoxTypeFiel()
}
/************************ free, skip *************************/
func BoxTypeFree() BoxType { return StrToBoxType("free") }
func BoxTypeSkip() BoxType { return StrToBoxType("skip") }
func init() {
AddBoxDef(&Free{})
AddBoxDef(&Skip{})
}
type FreeSpace struct {
Box
Data []uint8 `mp4:"0,size=8"`
}
type Free FreeSpace
func (*Free) GetType() BoxType {
return BoxTypeFree()
}
type Skip FreeSpace
func (*Skip) GetType() BoxType {
return BoxTypeSkip()
}
/*************************** frma ****************************/
func BoxTypeFrma() BoxType { return StrToBoxType("frma") }
func init() {
AddBoxDef(&Frma{})
}
// Frma is ISOBMFF frma box type
type Frma struct {
Box
DataFormat [4]byte `mp4:"0,size=8,string"`
}
// GetType returns the BoxType
func (*Frma) GetType() BoxType {
return BoxTypeFrma()
}
/*************************** ftyp ****************************/
func BoxTypeFtyp() BoxType { return StrToBoxType("ftyp") }
func init() {
AddBoxDef(&Ftyp{})
}
func BrandQT() [4]byte { return [4]byte{'q', 't', ' ', ' '} }
func BrandISOM() [4]byte { return [4]byte{'i', 's', 'o', 'm'} }
func BrandISO2() [4]byte { return [4]byte{'i', 's', 'o', '2'} }
func BrandISO3() [4]byte { return [4]byte{'i', 's', 'o', '3'} }
func BrandISO4() [4]byte { return [4]byte{'i', 's', 'o', '4'} }
func BrandISO5() [4]byte { return [4]byte{'i', 's', 'o', '5'} }
func BrandISO6() [4]byte { return [4]byte{'i', 's', 'o', '6'} }
func BrandISO7() [4]byte { return [4]byte{'i', 's', 'o', '7'} }
func BrandISO8() [4]byte { return [4]byte{'i', 's', 'o', '8'} }
func BrandISO9() [4]byte { return [4]byte{'i', 's', 'o', '9'} }
func BrandAVC1() [4]byte { return [4]byte{'a', 'v', 'c', '1'} }
func BrandMP41() [4]byte { return [4]byte{'m', 'p', '4', '1'} }
func BrandMP71() [4]byte { return [4]byte{'m', 'p', '7', '1'} }
// Ftyp is ISOBMFF ftyp box type
type Ftyp struct {
Box
MajorBrand [4]byte `mp4:"0,size=8,string"`
MinorVersion uint32 `mp4:"1,size=32"`
CompatibleBrands []CompatibleBrandElem `mp4:"2,size=32"` // reach to end of the box
}
type CompatibleBrandElem struct {
CompatibleBrand [4]byte `mp4:"0,size=8,string"`
}
func (ftyp *Ftyp) AddCompatibleBrand(cb [4]byte) {
if !ftyp.HasCompatibleBrand(cb) {
ftyp.CompatibleBrands = append(ftyp.CompatibleBrands, CompatibleBrandElem{
CompatibleBrand: cb,
})
}
}
func (ftyp *Ftyp) RemoveCompatibleBrand(cb [4]byte) {
for i := 0; i < len(ftyp.CompatibleBrands); {
if ftyp.CompatibleBrands[i].CompatibleBrand != cb {
i++
continue
}
ftyp.CompatibleBrands[i] = ftyp.CompatibleBrands[len(ftyp.CompatibleBrands)-1]
ftyp.CompatibleBrands = ftyp.CompatibleBrands[:len(ftyp.CompatibleBrands)-1]
}
}
func (ftyp *Ftyp) HasCompatibleBrand(cb [4]byte) bool {
for i := range ftyp.CompatibleBrands {
if ftyp.CompatibleBrands[i].CompatibleBrand == cb {
return true
}
}
return false
}
// GetType returns the BoxType
func (*Ftyp) GetType() BoxType {
return BoxTypeFtyp()
}
/*************************** hdlr ****************************/
func BoxTypeHdlr() BoxType { return StrToBoxType("hdlr") }
func init() {
AddBoxDef(&Hdlr{}, 0)
}
// Hdlr is ISOBMFF hdlr box type
type Hdlr struct {
FullBox `mp4:"0,extend"`
// Predefined corresponds to component_type of QuickTime.
// pre_defined of ISO-14496 has always zero,
// however component_type has "mhlr" or "dhlr".
PreDefined uint32 `mp4:"1,size=32"`
HandlerType [4]byte `mp4:"2,size=8,string"`
Reserved [3]uint32 `mp4:"3,size=32,const=0"`
Name string `mp4:"4,string"`
}
// GetType returns the BoxType
func (*Hdlr) GetType() BoxType {
return BoxTypeHdlr()
}
func (hdlr *Hdlr) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, ctx Context) (rbits uint64, override bool, err error) {
switch name {
case "Name":
return hdlr.OnReadName(r, leftBits, ctx)
default:
return 0, false, nil
}
}
func (hdlr *Hdlr) OnReadName(r bitio.ReadSeeker, leftBits uint64, ctx Context) (rbits uint64, override bool, err error) {
size := leftBits / 8
if size == 0 {
hdlr.Name = ""
return 0, true, nil
}
if !readerHasSize(r, size) {
return 0, false, fmt.Errorf("not enough bits")
}
buf := make([]byte, size)
if _, err := io.ReadFull(r, buf); err != nil {
return 0, false, err
}
plen := buf[0]
if hdlr.PreDefined != 0 && size >= 2 && size == uint64(plen+1) {
// Pascal-style String
hdlr.Name = string(buf[1 : plen+1])
} else {
// C-style String
clen := 0
for _, c := range buf {
if c == 0x00 {
break
}
clen++
}
hdlr.Name = string(buf[:clen])
}
return leftBits, true, nil
}
/*************************** hvcC ****************************/
func BoxTypeHvcC() BoxType { return StrToBoxType("hvcC") }
func init() {
AddBoxDef(&HvcC{})
}
type HEVCNalu struct {
BaseCustomFieldObject
Length uint16 `mp4:"0,size=16"`
NALUnit []byte `mp4:"1,size=8,len=dynamic"`
}
func (s HEVCNalu) GetFieldLength(name string, ctx Context) uint {
switch name {
case "NALUnit":
return uint(s.Length)
}
return 0
}
type HEVCNaluArray struct {
BaseCustomFieldObject
Completeness bool `mp4:"0,size=1"`
Reserved bool `mp4:"1,size=1"`
NaluType uint8 `mp4:"2,size=6"`
NumNalus uint16 `mp4:"3,size=16"`
Nalus []HEVCNalu `mp4:"4,len=dynamic"`
}
func (a HEVCNaluArray) GetFieldLength(name string, ctx Context) uint {
switch name {
case "Nalus":
return uint(a.NumNalus)
}
return 0
}
type HvcC struct {
Box
ConfigurationVersion uint8 `mp4:"0,size=8"`
GeneralProfileSpace uint8 `mp4:"1,size=2"`
GeneralTierFlag bool `mp4:"2,size=1"`
GeneralProfileIdc uint8 `mp4:"3,size=5"`
GeneralProfileCompatibility [32]bool `mp4:"4,size=1"`
GeneralConstraintIndicator [6]uint8 `mp4:"5,size=8"`
GeneralLevelIdc uint8 `mp4:"6,size=8"`
Reserved1 uint8 `mp4:"7,size=4,const=15"`
MinSpatialSegmentationIdc uint16 `mp4:"8,size=12"`
Reserved2 uint8 `mp4:"9,size=6,const=63"`
ParallelismType uint8 `mp4:"10,size=2"`
Reserved3 uint8 `mp4:"11,size=6,const=63"`
ChromaFormatIdc uint8 `mp4:"12,size=2"`
Reserved4 uint8 `mp4:"13,size=5,const=31"`
BitDepthLumaMinus8 uint8 `mp4:"14,size=3"`
Reserved5 uint8 `mp4:"15,size=5,const=31"`
BitDepthChromaMinus8 uint8 `mp4:"16,size=3"`
AvgFrameRate uint16 `mp4:"17,size=16"`
ConstantFrameRate uint8 `mp4:"18,size=2"`
NumTemporalLayers uint8 `mp4:"19,size=2"`
TemporalIdNested uint8 `mp4:"20,size=2"`
LengthSizeMinusOne uint8 `mp4:"21,size=2"`
NumOfNaluArrays uint8 `mp4:"22,size=8"`
NaluArrays []HEVCNaluArray `mp4:"23,len=dynamic"`
}
func (HvcC) GetType() BoxType {
return BoxTypeHvcC()
}
func (hvcc HvcC) GetFieldLength(name string, ctx Context) uint {
switch name {
case "NaluArrays":
return uint(hvcc.NumOfNaluArrays)
}
return 0
}
/*************************** mdat ****************************/
func BoxTypeMdat() BoxType { return StrToBoxType("mdat") }
func init() {
AddBoxDef(&Mdat{})
}
// Mdat is ISOBMFF mdat box type
type Mdat struct {
Box
Data []byte `mp4:"0,size=8"`
}
// GetType returns the BoxType
func (*Mdat) GetType() BoxType {
return BoxTypeMdat()
}
/*************************** mdhd ****************************/
func BoxTypeMdhd() BoxType { return StrToBoxType("mdhd") }
func init() {
AddBoxDef(&Mdhd{}, 0, 1)
}
// Mdhd is ISOBMFF mdhd box type
type Mdhd struct {
FullBox `mp4:"0,extend"`
CreationTimeV0 uint32 `mp4:"1,size=32,ver=0"`
ModificationTimeV0 uint32 `mp4:"2,size=32,ver=0"`
CreationTimeV1 uint64 `mp4:"3,size=64,ver=1"`
ModificationTimeV1 uint64 `mp4:"4,size=64,ver=1"`
Timescale uint32 `mp4:"5,size=32"`
DurationV0 uint32 `mp4:"6,size=32,ver=0"`
DurationV1 uint64 `mp4:"7,size=64,ver=1"`
//
Pad bool `mp4:"8,size=1,hidden"`
Language [3]byte `mp4:"9,size=5,iso639-2"` // ISO-639-2/T language code
PreDefined uint16 `mp4:"10,size=16"`
}
// GetType returns the BoxType
func (*Mdhd) GetType() BoxType {
return BoxTypeMdhd()
}
func (mdhd *Mdhd) GetCreationTime() uint64 {
switch mdhd.GetVersion() {
case 0:
return uint64(mdhd.CreationTimeV0)
case 1:
return mdhd.CreationTimeV1
default:
return 0
}
}
func (mdhd *Mdhd) GetModificationTime() uint64 {
switch mdhd.GetVersion() {
case 0:
return uint64(mdhd.ModificationTimeV0)
case 1:
return mdhd.ModificationTimeV1
default:
return 0
}
}
func (mdhd *Mdhd) GetDuration() uint64 {
switch mdhd.GetVersion() {
case 0:
return uint64(mdhd.DurationV0)
case 1:
return mdhd.DurationV1
default:
return 0
}
}
/*************************** mdia ****************************/
func BoxTypeMdia() BoxType { return StrToBoxType("mdia") }
func init() {
AddBoxDef(&Mdia{})
}
// Mdia is ISOBMFF mdia box type
type Mdia struct {
Box
}
// GetType returns the BoxType
func (*Mdia) GetType() BoxType {
return BoxTypeMdia()
}
/*************************** mehd ****************************/
func BoxTypeMehd() BoxType { return StrToBoxType("mehd") }
func init() {
AddBoxDef(&Mehd{}, 0, 1)
}
// Mehd is ISOBMFF mehd box type
type Mehd struct {
FullBox `mp4:"0,extend"`
FragmentDurationV0 uint32 `mp4:"1,size=32,ver=0"`
FragmentDurationV1 uint64 `mp4:"2,size=64,ver=1"`
}
// GetType returns the BoxType
func (*Mehd) GetType() BoxType {
return BoxTypeMehd()
}
func (mdhd *Mehd) GetFragmentDuration() uint64 {
switch mdhd.GetVersion() {
case 0:
return uint64(mdhd.FragmentDurationV0)
case 1:
return mdhd.FragmentDurationV1
default:
return 0
}
}
/*************************** meta ****************************/
func BoxTypeMeta() BoxType { return StrToBoxType("meta") }
func init() {
AddBoxDef(&Meta{}, 0)
}
// Meta is ISOBMFF meta box type
type Meta struct {
FullBox `mp4:"0,extend"`
}
// GetType returns the BoxType
func (*Meta) GetType() BoxType {
return BoxTypeMeta()
}
func (meta *Meta) BeforeUnmarshal(r io.ReadSeeker, size uint64, ctx Context) (n uint64, override bool, err error) {
// for Apple Quick Time
buf := make([]byte, 4)
if _, err := io.ReadFull(r, buf); err != nil {
return 0, false, err
}
if _, err := r.Seek(-int64(len(buf)), io.SeekCurrent); err != nil {
return 0, false, err
}
if buf[0]|buf[1]|buf[2]|buf[3] != 0x00 {
meta.Version = 0
meta.Flags = [3]byte{0, 0, 0}
return 0, true, nil
}
return 0, false, nil
}
/*************************** mfhd ****************************/
func BoxTypeMfhd() BoxType { return StrToBoxType("mfhd") }
func init() {
AddBoxDef(&Mfhd{}, 0)
}
// Mfhd is ISOBMFF mfhd box type
type Mfhd struct {
FullBox `mp4:"0,extend"`
SequenceNumber uint32 `mp4:"1,size=32"`
}
// GetType returns the BoxType
func (*Mfhd) GetType() BoxType {
return BoxTypeMfhd()
}
/*************************** mfra ****************************/
func BoxTypeMfra() BoxType { return StrToBoxType("mfra") }
func init() {
AddBoxDef(&Mfra{})
}
// Mfra is ISOBMFF mfra box type
type Mfra struct {
Box
}
// GetType returns the BoxType
func (*Mfra) GetType() BoxType {
return BoxTypeMfra()
}
/*************************** mfro ****************************/
func BoxTypeMfro() BoxType { return StrToBoxType("mfro") }
func init() {
AddBoxDef(&Mfro{}, 0)
}
// Mfro is ISOBMFF mfro box type
type Mfro struct {
FullBox `mp4:"0,extend"`
Size uint32 `mp4:"1,size=32"`
}
// GetType returns the BoxType
func (*Mfro) GetType() BoxType {
return BoxTypeMfro()
}
/*************************** minf ****************************/
func BoxTypeMinf() BoxType { return StrToBoxType("minf") }
func init() {
AddBoxDef(&Minf{})
}
// Minf is ISOBMFF minf box type
type Minf struct {
Box
}
// GetType returns the BoxType
func (*Minf) GetType() BoxType {
return BoxTypeMinf()
}
/*************************** moof ****************************/
func BoxTypeMoof() BoxType { return StrToBoxType("moof") }
func init() {
AddBoxDef(&Moof{})
}
// Moof is ISOBMFF moof box type
type Moof struct {
Box
}
// GetType returns the BoxType
func (*Moof) GetType() BoxType {