mp4-rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +24 -0
  3. data/Gemfile.lock +149 -0
  4. data/README.md +195 -0
  5. data/Rakefile +8 -0
  6. data/bin/build_mp4_xlsx.rb +35 -0
  7. data/bin/divide_mp4_to_segments.rb +52 -0
  8. data/lib/m4s/binary/ftyp.rb +11 -0
  9. data/lib/m4s/binary/mdat.rb +0 -0
  10. data/lib/m4s/binary/mfhd.rb +18 -0
  11. data/lib/m4s/binary/mvhd.rb +39 -0
  12. data/lib/m4s/binary/sidx.rb +38 -0
  13. data/lib/m4s/binary/styp.rb +17 -0
  14. data/lib/m4s/binary/tfdt.rb +25 -0
  15. data/lib/m4s/binary/tfhd.rb +38 -0
  16. data/lib/m4s/binary/trex.rb +25 -0
  17. data/lib/m4s/binary/trun.rb +30 -0
  18. data/lib/m4s/dash/manifest.rb +149 -0
  19. data/lib/m4s/layout/atom.rb +44 -0
  20. data/lib/m4s/layout/builder.rb +32 -0
  21. data/lib/m4s/layout/container.rb +59 -0
  22. data/lib/m4s/layout/ctts.rb +20 -0
  23. data/lib/m4s/layout/dinf.rb +17 -0
  24. data/lib/m4s/layout/elst.rb +33 -0
  25. data/lib/m4s/layout/ftyp.rb +21 -0
  26. data/lib/m4s/layout/hdlr.rb +22 -0
  27. data/lib/m4s/layout/init_mp4_builder.rb +57 -0
  28. data/lib/m4s/layout/mdat.rb +61 -0
  29. data/lib/m4s/layout/mdhd.rb +25 -0
  30. data/lib/m4s/layout/mfhd.rb +17 -0
  31. data/lib/m4s/layout/mvhd.rb +32 -0
  32. data/lib/m4s/layout/sidx.rb +36 -0
  33. data/lib/m4s/layout/stco.rb +21 -0
  34. data/lib/m4s/layout/stsc.rb +20 -0
  35. data/lib/m4s/layout/stsd.rb +17 -0
  36. data/lib/m4s/layout/stss.rb +20 -0
  37. data/lib/m4s/layout/stsz.rb +19 -0
  38. data/lib/m4s/layout/stts.rb +20 -0
  39. data/lib/m4s/layout/styp.rb +17 -0
  40. data/lib/m4s/layout/tfdt.rb +21 -0
  41. data/lib/m4s/layout/tfhd.rb +17 -0
  42. data/lib/m4s/layout/tkhd.rb +34 -0
  43. data/lib/m4s/layout/trex.rb +33 -0
  44. data/lib/m4s/layout/trun.rb +89 -0
  45. data/lib/m4s/layout/vsmhd.rb +51 -0
  46. data/lib/m4s/m3u8/general_playlist.rb +52 -0
  47. data/lib/m4s/m3u8/media_playlist.rb +32 -0
  48. data/lib/mp4/binary/avc1.rb +98 -0
  49. data/lib/mp4/binary/box_head.rb +8 -0
  50. data/lib/mp4/binary/co64.rb +11 -0
  51. data/lib/mp4/binary/codec.rb +8 -0
  52. data/lib/mp4/binary/ctts.rb +14 -0
  53. data/lib/mp4/binary/ctts_reader.rb +5 -0
  54. data/lib/mp4/binary/dinf.rb +5 -0
  55. data/lib/mp4/binary/dref.rb +5 -0
  56. data/lib/mp4/binary/elst.rb +16 -0
  57. data/lib/mp4/binary/fixed_point16.rb +19 -0
  58. data/lib/mp4/binary/fixed_point8.rb +19 -0
  59. data/lib/mp4/binary/ftyp.rb +9 -0
  60. data/lib/mp4/binary/gmhd.rb +5 -0
  61. data/lib/mp4/binary/hdlr.rb +13 -0
  62. data/lib/mp4/binary/hev1.rb +73 -0
  63. data/lib/mp4/binary/hmhd.rb +14 -0
  64. data/lib/mp4/binary/iods.rb +5 -0
  65. data/lib/mp4/binary/mdhd.rb +18 -0
  66. data/lib/mp4/binary/mp4a.rb +76 -0
  67. data/lib/mp4/binary/mvhd.rb +39 -0
  68. data/lib/mp4/binary/nmhd.rb +8 -0
  69. data/lib/mp4/binary/saio.rb +25 -0
  70. data/lib/mp4/binary/saiz.rb +17 -0
  71. data/lib/mp4/binary/sbgp.rb +5 -0
  72. data/lib/mp4/binary/sdtp.rb +18 -0
  73. data/lib/mp4/binary/senc.rb +12 -0
  74. data/lib/mp4/binary/sgpd.rb +5 -0
  75. data/lib/mp4/binary/smhd.rb +11 -0
  76. data/lib/mp4/binary/stco.rb +13 -0
  77. data/lib/mp4/binary/stco_reader.rb +5 -0
  78. data/lib/mp4/binary/sthd.rb +8 -0
  79. data/lib/mp4/binary/stsc.rb +15 -0
  80. data/lib/mp4/binary/stsc_reader.rb +5 -0
  81. data/lib/mp4/binary/stsd.rb +5 -0
  82. data/lib/mp4/binary/stsd_atom.rb +11 -0
  83. data/lib/mp4/binary/stsd_reader.rb +5 -0
  84. data/lib/mp4/binary/stss.rb +13 -0
  85. data/lib/mp4/binary/stss_reader.rb +5 -0
  86. data/lib/mp4/binary/stsz.rb +18 -0
  87. data/lib/mp4/binary/stsz_reader.rb +5 -0
  88. data/lib/mp4/binary/stts.rb +14 -0
  89. data/lib/mp4/binary/stts_reader.rb +5 -0
  90. data/lib/mp4/binary/tkhd.rb +46 -0
  91. data/lib/mp4/binary/udta.rb +5 -0
  92. data/lib/mp4/binary/vmhd.rb +11 -0
  93. data/lib/mp4/cache/memory.rb +328 -0
  94. data/lib/mp4/cache/sqlite.rb +348 -0
  95. data/lib/mp4/cache.rb +13 -0
  96. data/lib/mp4/constants.rb +87 -0
  97. data/lib/mp4/ext/refinements.rb +19 -0
  98. data/lib/mp4/layout/atom.rb +47 -0
  99. data/lib/mp4/layout/base.rb +10 -0
  100. data/lib/mp4/layout/builder.rb +16 -0
  101. data/lib/mp4/layout/container.rb +59 -0
  102. data/lib/mp4/layout/ctts.rb +35 -0
  103. data/lib/mp4/layout/dinf.rb +15 -0
  104. data/lib/mp4/layout/elst.rb +33 -0
  105. data/lib/mp4/layout/free.rb +20 -0
  106. data/lib/mp4/layout/ftyp.rb +21 -0
  107. data/lib/mp4/layout/hdlr.rb +20 -0
  108. data/lib/mp4/layout/mdat.rb +33 -0
  109. data/lib/mp4/layout/mdhd.rb +27 -0
  110. data/lib/mp4/layout/moov.rb +58 -0
  111. data/lib/mp4/layout/mvhd.rb +46 -0
  112. data/lib/mp4/layout/stco.rb +37 -0
  113. data/lib/mp4/layout/stsc.rb +27 -0
  114. data/lib/mp4/layout/stsd.rb +15 -0
  115. data/lib/mp4/layout/stss.rb +22 -0
  116. data/lib/mp4/layout/stsz.rb +39 -0
  117. data/lib/mp4/layout/stts.rb +35 -0
  118. data/lib/mp4/layout/tkhd.rb +45 -0
  119. data/lib/mp4/layout/vsmhd.rb +49 -0
  120. data/lib/mp4/layout.rb +3 -0
  121. data/lib/mp4/metadata/memoize/ftyp.rb +13 -0
  122. data/lib/mp4/metadata/memoize/stbl/binary_stsd.rb +13 -0
  123. data/lib/mp4/metadata/memoize/stbl/chunks.rb +46 -0
  124. data/lib/mp4/metadata/memoize/stbl/codec.rb +82 -0
  125. data/lib/mp4/metadata/memoize/stbl/composition_offset_calculator.rb +31 -0
  126. data/lib/mp4/metadata/memoize/stbl/delta_calculator.rb +29 -0
  127. data/lib/mp4/metadata/memoize/stbl/sample_to_chunk_calculator.rb +63 -0
  128. data/lib/mp4/metadata/memoize/stbl/samples.rb +80 -0
  129. data/lib/mp4/metadata/memoize/track.rb +98 -0
  130. data/lib/mp4/metadata/memoize/tracks.rb +11 -0
  131. data/lib/mp4/metadata/service.rb +30 -0
  132. data/lib/mp4/metadata/summary.rb +11 -0
  133. data/lib/mp4/nolan/service/sound.rb +36 -0
  134. data/lib/mp4/nolan/service/track.rb +9 -0
  135. data/lib/mp4/nolan/service/video.rb +35 -0
  136. data/lib/mp4/nolan/service.rb +84 -0
  137. data/lib/mp4/nolan.rb +3 -0
  138. data/lib/mp4/parser/main_boxes.rb +43 -0
  139. data/lib/mp4/parser/moov.rb +40 -0
  140. data/lib/mp4/parser/service.rb +47 -0
  141. data/lib/mp4/parser/track.rb +56 -0
  142. data/lib/mp4/rb/version.rb +7 -0
  143. data/lib/mp4/rb.rb +10 -0
  144. data/lib/mp4/source/base.rb +20 -0
  145. data/lib/mp4/source/local.rb +79 -0
  146. data/lib/mp4/source/s3.rb +118 -0
  147. data/lib/mp4/source/url.rb +130 -0
  148. data/lib/mp4/source.rb +23 -0
  149. data/lib/mp4/structure/service.rb +13 -0
  150. data/lib/mp4/xlsx/builder.rb +44 -0
  151. data/lib/mp4.rb +222 -0
  152. data/mp4-rb.gemspec +68 -0
  153. data/sig/mp4/rb.rbs +6 -0
  154. data/todo.txt +4 -0
  155. metadata +323 -0
@@ -0,0 +1,19 @@
1
+ module MP4::Binary
2
+ class FixedPoint8 < BinData::BasePrimitive
3
+ def value_to_binary_string(value)
4
+ value = (value.to_i * (2.0**8)).to_i
5
+
6
+ BinData::Int16be.new(value).to_binary_s
7
+ end
8
+
9
+ def read_and_return_value(io)
10
+ raw_value = BinData::Int16be.read read_uint32(io)
11
+
12
+ (raw_value / (2.0**8)).to_i
13
+ end
14
+
15
+ def read_uint32(io)
16
+ io.readbytes(2)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module MP4::Binary
2
+ class Ftyp < BinData::Record
3
+ endian :big
4
+
5
+ string :major_brand, length: 4
6
+ uint32 :minor_version
7
+ rest :compatible_brands
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Gmhd < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module MP4::Binary
2
+ class Hdlr < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ uint32 :pre_defined, value: 0
9
+ string :handler_type, length: 4
10
+ skip length: 4 * 3
11
+ rest :handler_name
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ module MP4::Binary
2
+ class FieldInfoBox < BinData::Record
3
+ endian :big
4
+ uint32 :atom_size
5
+ string :atom_type, length: 4, assert: "fiel"
6
+ uint8 :counts
7
+ uint8 :order
8
+ end
9
+
10
+ class PixelAspectRatioBox < BinData::Record
11
+ endian :big
12
+ uint32 :atom_size
13
+ string :atom_type, length: 4, assert: "pasp"
14
+ uint32 :h_spacing
15
+ uint32 :v_spacing
16
+ end
17
+
18
+ class BitRateBox < BinData::Record
19
+ endian :big
20
+ uint32 :atom_size
21
+ string :atom_type, length: 4, assert: "btrt"
22
+ uint32 :buffer_size_db
23
+ uint32 :max_bitrate
24
+ uint32 :avg_bitrate
25
+ end
26
+
27
+ class CodecOptions < BinData::Record
28
+ endian :big
29
+ array :reserved1, type: :uint8, initial_length: 6
30
+ uint16 :data_reference_index
31
+ uint16 :reserved2
32
+ uint16 :reserved3
33
+ uint32 :reserved4
34
+ uint16 :reserved5
35
+ uint16 :reserved6
36
+ uint32 :reserved7
37
+ uint16 :width
38
+ uint16 :height
39
+ uint32 :horizontal_resolution
40
+ uint32 :vertical_resolution
41
+ uint32 :reserved8
42
+ uint16 :frame_count
43
+ string :compressor_name, length: 32
44
+ uint16 :bit_depth
45
+ int16 :reserved9
46
+ rest :all_rest
47
+ end
48
+
49
+ module Hev1
50
+
51
+ def self.read(bytes)
52
+ hev1 = CodecOptions.read(bytes)
53
+ pasp = find_atom(bytes, 'pasp', PixelAspectRatioBox)
54
+ bitrate = find_atom(bytes, 'btrt', BitRateBox)
55
+
56
+ {
57
+ width: hev1.width,
58
+ height: hev1.height,
59
+ pasp: pasp,
60
+ bitrate: bitrate,
61
+ }
62
+ end
63
+
64
+ def self.find_atom(bytes, atom_name, atom_handler)
65
+ atom_name_position = bytes.index(atom_name)
66
+ atom_start_pos = atom_name_position - 4
67
+ atom_size = BinData::Uint32be.read(bytes[atom_start_pos..atom_start_pos + 4]).to_i
68
+ atom_bytes = bytes[atom_start_pos..atom_start_pos + 4 + atom_size]
69
+
70
+ atom_handler.read(atom_bytes)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,14 @@
1
+ module MP4::Binary
2
+ class Hmhd < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version, value: 0
6
+ bit24 :flags, value: 0
7
+
8
+ uint16 :max_pdu_size
9
+ uint16 :avg_pdu_size
10
+ uint32 :max_bitrate
11
+ uint32 :avg_bitrate
12
+ uint32 :reserved, value: 0
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Iods < ::BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module MP4::Binary
2
+ class Mdhd < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ uint32 :creation_time
9
+ uint32 :modification_time
10
+ uint32 :timescale
11
+ uint32 :duration
12
+
13
+ bit1 :pad, value: 0
14
+ array :language, initial_length: 3, type: :bit5
15
+
16
+ skip length: 2
17
+ end
18
+ end
@@ -0,0 +1,76 @@
1
+ module MP4::Binary
2
+ class Base128Size < BinData::Primitive
3
+ endian :big
4
+ array :size_bytes, type: :uint8, read_until: -> { (element & 0x80).zero? }
5
+
6
+ def get
7
+ size_bytes.inject(0) { |acc, byte| (acc << 7) | (byte & 0x7f) }
8
+ end
9
+
10
+ def set(v)
11
+ self.size_bytes = []
12
+ while v.positive?
13
+ self.size_bytes.unshift((v & 0x7f) | 0x80)
14
+ v >>= 7
15
+ end
16
+ self.size_bytes[-1] &= 0x7f
17
+ end
18
+ end
19
+
20
+ class DecoderSpecificInfo < BinData::Record
21
+ endian :big
22
+ uint8 :tag, assert: 0x05 # Tag for DecoderSpecificInfo
23
+ base128_size :len
24
+ string :info, read_length: :len
25
+ end
26
+
27
+ class DecoderConfigDescriptor < BinData::Record
28
+ endian :big
29
+ uint8 :tag, assert: 0x04
30
+ base128_size :len
31
+ uint8 :object_type_indication
32
+ bit6 :stream_type
33
+ bit1 :up_stream
34
+ bit1 :reserved
35
+ uint24 :buffer_size_db
36
+ uint32 :max_bitrate
37
+ uint32 :avg_bitrate
38
+ decoder_specific_info :dec_specific_info
39
+ end
40
+
41
+ class EsDescriptor < BinData::Record
42
+ endian :big
43
+ uint8 :tag, assert: 0x03 # Tag for ESDescriptor
44
+ base128_size :len
45
+ uint16 :es_id
46
+ bit1 :stream_dependence_flag
47
+ bit1 :url_flag
48
+ bit1 :ocr_stream_flag
49
+ bit5 :stream_priority
50
+ decoder_config_descriptor :dec_config_desc
51
+ end
52
+
53
+ class Esds < BinData::Record
54
+ endian :big
55
+ uint32 :atom_size
56
+ string :atom_type, read_length: 4, assert: -> { value == "esds" }
57
+ uint8 :version
58
+ bit24 :flags
59
+ es_descriptor :es_descriptor
60
+ end
61
+
62
+ class Mp4a < BinData::Record
63
+ endian :big
64
+ array :reserved1, type: :uint8, initial_length: 6
65
+ uint16 :data_reference_index
66
+ uint16 :version
67
+ uint16 :revision_level
68
+ uint32 :vendor
69
+ uint16 :channel_count
70
+ uint16 :sample_size
71
+ uint16 :compression_id
72
+ uint16 :packet_size
73
+ uint32 :sample_rate
74
+ esds :esds
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ module MP4::Binary
2
+ class Mvhd < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ uint32 :creation_time
9
+ uint32 :modification_time
10
+ uint32 :timescale
11
+ uint32 :duration
12
+
13
+ fixed_point16 :rate
14
+ fixed_point8 :volume
15
+
16
+ skip length: 2 + 4 + 4
17
+
18
+ array :matrix, initial_length: 9, type: :uint32
19
+
20
+ skip length: 4 * 6
21
+
22
+ uint32 :next_track_id
23
+ end
24
+ end
25
+ # ISO/IEC 14496-12:2015(E)
26
+ # SEMANTICS:
27
+ # `version` - is an integer that specifies the version of this box (0 or 1 in this specification) creation_time is an integer that declares the creation time of the presentation (in seconds
28
+ # `since` - midnight, Jan. 1, 1904, in UTC time)
29
+ # `modification_time` - is an integer that declares the most recent time the presentation was
30
+ # `modified` - (in seconds since midnight, Jan. 1, 1904, in UTC time)
31
+ # `timescale` - is an integer that specifies the time‐scale for the entire presentation; this is the
32
+ # `number` - of time units that pass in one second. For example, a time coordinate system that
33
+ # `measures` - time in sixtieths of a second has a time scale of 60.
34
+ # `duration` - is an integer that declares length of the presentation (in the indicated timescale). This
35
+ # `property` - is derived from the presentation’s tracks: the value of this field corresponds to the duration of the longest track in the presentation. If the duration cannot be determined then duration is set to all 1s.
36
+ # `rate` - is a fixed point 16.16 number that indicates the preferred rate to play the presentation; 1.0 (0x00010000) is normal forward playback
37
+ # `volume` - is a fixed point 8.8 number that indicates the preferred playback volume. 1.0 (0x0100) is full volume.
38
+ # `matrix - provides a transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex values (0,0,0x40000000).
39
+ # `next_track_ID` - is a non‐zero integer that indicates a value to use for the track ID of the next track to be added to this presentation. Zero is not a valid track ID value. The value of next_track_ID shall be larger than the largest track‐ID in use. If this value is equal to all 1s (32‐bit maxint), and a new media track is to be added, then a search must be made in the file for an unused track identifier.
@@ -0,0 +1,8 @@
1
+ module MP4::Binary
2
+ class Nmhd < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version, value: 0
6
+ bit24 :flags, value: 0
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ module MP4::Binary
2
+ class Saio < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version
6
+ bit24 :flags
7
+
8
+ uint32 :aux_info_type, onlyif: -> { (flags & 0x000001).nonzero? }
9
+ uint32 :aux_info_type_parameter, onlyif: -> { (flags & 0x000001).nonzero? }
10
+
11
+ uint32 :entry_count
12
+ array :offsets_32,
13
+ type: :uint32,
14
+ initial_length: :entry_count,
15
+ onlyif: -> { version.zero? }
16
+ array :offsets_64,
17
+ type: :uint64,
18
+ initial_length: :entry_count,
19
+ onlyif: -> { version == 1 }
20
+
21
+ def offsets
22
+ version.zero? ? offsets_32.to_a : offsets_64.to_a
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module MP4::Binary
2
+ class Saiz < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version
6
+ bit24 :flags
7
+
8
+ uint32 :aux_info_type, onlyif: -> { (flags & 0x000001).nonzero? }
9
+ uint32 :aux_info_type_parameter, onlyif: -> { (flags & 0x000001).nonzero? }
10
+
11
+ uint8 :default_sample_info_size
12
+ uint32 :sample_count
13
+ array :sample_info_sizes,
14
+ type: :uint8,
15
+ initial_length: -> { default_sample_info_size.zero? ? sample_count : 0 }
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Sbgp < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module MP4::Binary
2
+ class SampleDependency < BinData::Record
3
+ endian :big
4
+
5
+ bit2 :reserved
6
+ bit2 :sample_depends_on
7
+ bit2 :sample_is_depended_on
8
+ bit2 :sample_has_redundancy
9
+ end
10
+
11
+ class Sdtp < BinData::Record
12
+ endian :big
13
+
14
+ array :samples, read_until: :eof do
15
+ sample_dependency :sample_dependency
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module MP4::Binary
2
+ class Senc < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version
6
+ bit24 :flags
7
+
8
+ uint32 :sample_count
9
+
10
+ rest :raw_entries
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Sgpd < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module MP4::Binary
2
+ class Smhd < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ int16 :balance, value: 0
9
+ uint16 :reserved, value: 0
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module MP4::Binary
2
+ class Stco < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8, value: [0, 0, 0]
7
+
8
+ uint32 :chunks_count
9
+ array :offsets, initial_length: :chunks_count do
10
+ uint32 :chunk_offset
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class StcoReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module MP4::Binary
2
+ class Sthd < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version, value: 0
6
+ bit24 :flags, value: 0
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module MP4::Binary
2
+ class Stsc < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8, value: [0, 0, 0]
7
+
8
+ uint32 :chunk_count
9
+ array :table, initial_length: :chunk_count do
10
+ uint32 :first_chunk
11
+ uint32 :samples_per_chunk
12
+ uint32 :sample_description_index
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class StscReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Stsd < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module MP4::Binary
2
+ class StsdAtom < BinData::Record
3
+ endian :big
4
+
5
+ uint8 :version
6
+ bit24 :flags
7
+
8
+ uint32 :codecs_count
9
+ array :codecs, type: :codec, initial_length: :codecs_count
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class StsdReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module MP4::Binary
2
+ class Stss < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8, value: [0, 0, 0]
7
+
8
+ uint32 :sync_samples_count
9
+ array :sync_sample, initial_length: :sync_samples_count do
10
+ uint32 :sample_number
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class StssReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module MP4::Binary
2
+ class Stsz < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8, value: [0, 0, 0]
7
+
8
+ uint32 :sample_size
9
+ uint32 :sample_count
10
+ array :sample_sizes, initial_length: :sample_count, onlyif: :has_list? do
11
+ uint32 :sample_size
12
+ end
13
+
14
+ def has_list?
15
+ sample_size.zero?
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class StszReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module MP4::Binary
2
+ class Stts < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8, value: [0, 0, 0]
7
+
8
+ uint32 :entries_count
9
+ array :time_to_sample, initial_length: :entries_count do
10
+ uint32 :sample_count
11
+ uint32 :sample_delta
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class SttsReader < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ module MP4::Binary
2
+ class Tkhd < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ uint32 :creation_time
9
+ uint32 :modification_time
10
+ uint32 :track_id
11
+ skip length: 4
12
+ uint32 :duration
13
+
14
+ skip length: 4 + 4
15
+
16
+ int16 :layer
17
+ int16 :alternate_group
18
+ fixed_point8 :volume
19
+
20
+ skip length: 2
21
+
22
+ array :matrix, initial_length: 9, type: :uint32
23
+
24
+ fixed_point16 :width
25
+ fixed_point16 :height
26
+ end
27
+ end
28
+ # ISO/IEC 14496-12:2015(E)
29
+ # SEMANTICS:
30
+ # `version` is an integer that specifies the version of this box (0 or 1 in this specification)
31
+ # `flags` is a 24‐bit integer with flags; the following values are defined:
32
+ # - `Track_enabled`: Indicates that the track is enabled. Flag value is 0x000001. A disabled track (the low bit is zero) is treated as if it were not present.
33
+ # - `Track_in_movie`: Indicates that the track is used in the presentation. Flag value is 0x000002. Track_in_preview: Indicates that the track is used when previewing the presentation. Flag value is 0x000004.
34
+ # - `Track_size_is_aspect_ratio`: Indicates that the width and height fields are not expressed in pixel units. The values have the same units but these units are not specified. The values are only an indication of the desired aspect ratio. If the aspect ratios of this track and other related tracks are not identical, then the respective positioning of the tracks is undefined, possibly defined by external contexts. Flag value is 0x000008.
35
+ # `creation_time` is an integer that declares the creation time of this track (in seconds since midnight, Jan. 1, 1904, in UTC time).
36
+ # `modification_time` is an integer that declares the most recent time the track was modified (in seconds since midnight, Jan. 1, 1904, in UTC time).
37
+ # `track_ID` is an integer that uniquely identifies this track over the entire life‐time of this presentation. Track IDs are never re‐used and cannot be zero.
38
+ # `duration` is an integer that indicates the duration of this track (in the timescale indicated in the Movie Header Box). The value of this field is equal to the sum of the durations of all of the track’s edits. If there is no edit list, then the duration is the sum of the sample durations, converted into the timescale in the Movie Header Box. If the duration of this track cannot be determined then duration is set to all 1s.
39
+ # `layer` specifies the front‐to‐back ordering of video tracks; tracks with lower numbers are closer to the viewer. 0 is the normal value, and ‐1 would be in front of track 0, and so on.
40
+ # `alternate_group` is an integer that specifies a group or collection of tracks. If this field is 0 there is no information on possible relations to other tracks. If this field is not 0, it should be the same for tracks that contain alternate data for one another and different for tracks belonging to different such groups. Only one track within an alternate group should be played or streamed at any one time, and must be distinguishable from other tracks in the group via attributes such as bitrate, codec, language, packet size etc. A group may have only one member.
41
+ # `volume` is a fixed 8.8 value specifying the track's relative audio volume. Full volume is 1.0 (0x0100) and is the normal value. Its value is irrelevant for a purely visual track. Tracks may be composed by combining them according to their volume, and then using the overall Movie Header Box volume setting; or more complex audio composition (e.g. MPEG‐4 BIFS) may be used.
42
+ # `matrix` provides a transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex (0,0,0x40000000).
43
+ # `width` and `height` fixed‐point 16.16 values are track‐dependent as follows:
44
+ # For text and subtitle tracks, they may, depending on the coding format, describe the suggested size of the rendering area. For such tracks, the value 0x0 may also be used to indicate that the data may be rendered at any size, that no preferred size has been indicated and that the actual size may be determined by the external context or by reusing the width and height of another track. For those tracks, the flag track_size_is_aspect_ratio may also be used.
45
+ # For non‐visual tracks (e.g. audio), they should be set to zero.
46
+ # For all other tracks, they specify the track's visual presentation size. These need not be the same as the pixel dimensions of the images, which is documented in the sample description(s); all images in the sequence are scaled to this size, before any overall transformation of the track represented by the matrix. The pixel dimensions of the images are the default values.
@@ -0,0 +1,5 @@
1
+ module MP4::Binary
2
+ class Udta < BinData::Record
3
+ rest :content
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module MP4::Binary
2
+ class Vmhd < BinData::Record
3
+ endian :big
4
+
5
+ bit1 :version, value: 0
6
+ array :flags, initial_length: 3, type: :uint8
7
+
8
+ uint16 :graphicsmode, value: 0
9
+ array :opcolor, initial_length: 3, type: :uint16
10
+ end
11
+ end