bmff 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +183 -0
- data/Rakefile +9 -0
- data/bmff.gemspec +25 -0
- data/lib/bmff/binary_accessor.rb +186 -0
- data/lib/bmff/box/audio_sample_entry.rb +16 -0
- data/lib/bmff/box/base.rb +66 -0
- data/lib/bmff/box/bit_rate.rb +14 -0
- data/lib/bmff/box/chunk_large_offset.rb +16 -0
- data/lib/bmff/box/chunk_offset.rb +16 -0
- data/lib/bmff/box/clean_aperture.rb +20 -0
- data/lib/bmff/box/colour_information.rb +27 -0
- data/lib/bmff/box/compact_sample_size.rb +32 -0
- data/lib/bmff/box/composition_offset.rb +25 -0
- data/lib/bmff/box/composition_to_decode.rb +17 -0
- data/lib/bmff/box/container.rb +70 -0
- data/lib/bmff/box/copyright.rb +13 -0
- data/lib/bmff/box/data_entry_url.rb +12 -0
- data/lib/bmff/box/data_entry_urn.rb +13 -0
- data/lib/bmff/box/data_information.rb +12 -0
- data/lib/bmff/box/data_reference.rb +14 -0
- data/lib/bmff/box/degradation_priority.rb +19 -0
- data/lib/bmff/box/edit.rb +12 -0
- data/lib/bmff/box/edit_list.rb +27 -0
- data/lib/bmff/box/file_type.rb +17 -0
- data/lib/bmff/box/free_space.rb +6 -0
- data/lib/bmff/box/full.rb +11 -0
- data/lib/bmff/box/handler.rb +15 -0
- data/lib/bmff/box/hint_media_header.rb +16 -0
- data/lib/bmff/box/hint_sample_entry.rb +14 -0
- data/lib/bmff/box/level_assignment.rb +35 -0
- data/lib/bmff/box/map.rb +15 -0
- data/lib/bmff/box/media.rb +12 -0
- data/lib/bmff/box/media_data.rb +6 -0
- data/lib/bmff/box/media_header.rb +25 -0
- data/lib/bmff/box/media_information.rb +12 -0
- data/lib/bmff/box/meta_data_sample_entry.rb +5 -0
- data/lib/bmff/box/movie.rb +12 -0
- data/lib/bmff/box/movie_extends.rb +12 -0
- data/lib/bmff/box/movie_extends_header.rb +16 -0
- data/lib/bmff/box/movie_fragment.rb +12 -0
- data/lib/bmff/box/movie_fragment_header.rb +12 -0
- data/lib/bmff/box/movie_fragment_random_access.rb +12 -0
- data/lib/bmff/box/movie_fragment_random_access_offset.rb +12 -0
- data/lib/bmff/box/movie_header.rb +36 -0
- data/lib/bmff/box/null_media_header.rb +6 -0
- data/lib/bmff/box/padding_bits.rb +23 -0
- data/lib/bmff/box/pixel_aspect_ratio.rb +13 -0
- data/lib/bmff/box/progressive_download_info.rb +17 -0
- data/lib/bmff/box/sample_auxiliary_information_offsets.rb +24 -0
- data/lib/bmff/box/sample_auxiliary_information_sizes.rb +23 -0
- data/lib/bmff/box/sample_dependency_type.rb +26 -0
- data/lib/bmff/box/sample_description.rb +27 -0
- data/lib/bmff/box/sample_entry.rb +15 -0
- data/lib/bmff/box/sample_size.rb +19 -0
- data/lib/bmff/box/sample_table.rb +12 -0
- data/lib/bmff/box/sample_to_chunk.rb +20 -0
- data/lib/bmff/box/shadow_sync_sample.rb +18 -0
- data/lib/bmff/box/sound_media_header.rb +13 -0
- data/lib/bmff/box/sub_sample_information.rb +41 -0
- data/lib/bmff/box/sync_sample.rb +16 -0
- data/lib/bmff/box/text_meta_data_sample_entry.rb +18 -0
- data/lib/bmff/box/time_to_sample.rb +18 -0
- data/lib/bmff/box/track.rb +12 -0
- data/lib/bmff/box/track_extends.rb +17 -0
- data/lib/bmff/box/track_fragment.rb +12 -0
- data/lib/bmff/box/track_fragment_base_media_decode_time.rb +16 -0
- data/lib/bmff/box/track_fragment_header.rb +18 -0
- data/lib/bmff/box/track_fragment_random_access.rb +54 -0
- data/lib/bmff/box/track_group.rb +12 -0
- data/lib/bmff/box/track_group_type.rb +12 -0
- data/lib/bmff/box/track_header.rb +36 -0
- data/lib/bmff/box/track_reference.rb +12 -0
- data/lib/bmff/box/track_reference_type.rb +15 -0
- data/lib/bmff/box/track_run.rb +31 -0
- data/lib/bmff/box/track_selection.rb +16 -0
- data/lib/bmff/box/unknown.rb +5 -0
- data/lib/bmff/box/uri.rb +12 -0
- data/lib/bmff/box/uri_init.rb +15 -0
- data/lib/bmff/box/uri_meta_sample_entry.rb +24 -0
- data/lib/bmff/box/user_data.rb +12 -0
- data/lib/bmff/box/video_media_header.rb +13 -0
- data/lib/bmff/box/visual_sample_entry.rb +37 -0
- data/lib/bmff/box/xml_meta_data_sample_entry.rb +19 -0
- data/lib/bmff/box.rb +115 -0
- data/lib/bmff/file_container.rb +20 -0
- data/lib/bmff/version.rb +3 -0
- data/lib/bmff.rb +7 -0
- data/test/bmff/box/test_audio_sample_entry.rb +46 -0
- data/test/bmff/box/test_base.rb +37 -0
- data/test/bmff/box/test_bit_rate.rb +30 -0
- data/test/bmff/box/test_chunk_large_offset.rb +35 -0
- data/test/bmff/box/test_chunk_offset.rb +35 -0
- data/test/bmff/box/test_clean_aperture.rb +40 -0
- data/test/bmff/box/test_colour_information.rb +73 -0
- data/test/bmff/box/test_compact_sample_size.rb +99 -0
- data/test/bmff/box/test_composition_offset.rb +64 -0
- data/test/bmff/box/test_composition_to_decode.rb +38 -0
- data/test/bmff/box/test_copyright.rb +55 -0
- data/test/bmff/box/test_data_entry_url.rb +30 -0
- data/test/bmff/box/test_data_entry_urn.rb +32 -0
- data/test/bmff/box/test_data_information.rb +26 -0
- data/test/bmff/box/test_data_reference.rb +58 -0
- data/test/bmff/box/test_degradation_priority.rb +62 -0
- data/test/bmff/box/test_edit.rb +26 -0
- data/test/bmff/box/test_edit_list.rb +72 -0
- data/test/bmff/box/test_file_type.rb +30 -0
- data/test/bmff/box/test_free_space.rb +42 -0
- data/test/bmff/box/test_handler.rb +67 -0
- data/test/bmff/box/test_hint_media_header.rb +38 -0
- data/test/bmff/box/test_hint_sample_entry.rb +38 -0
- data/test/bmff/box/test_level_assignment.rb +50 -0
- data/test/bmff/box/test_media.rb +26 -0
- data/test/bmff/box/test_media_data.rb +25 -0
- data/test/bmff/box/test_media_header.rb +72 -0
- data/test/bmff/box/test_media_information.rb +26 -0
- data/test/bmff/box/test_movie.rb +26 -0
- data/test/bmff/box/test_movie_extends.rb +26 -0
- data/test/bmff/box/test_movie_extends_header.rb +52 -0
- data/test/bmff/box/test_movie_fragment.rb +26 -0
- data/test/bmff/box/test_movie_fragment_header.rb +30 -0
- data/test/bmff/box/test_movie_fragment_random_access.rb +26 -0
- data/test/bmff/box/test_movie_fragment_random_access_offset.rb +30 -0
- data/test/bmff/box/test_movie_header.rb +110 -0
- data/test/bmff/box/test_null_media_header.rb +28 -0
- data/test/bmff/box/test_padding_bits.rb +38 -0
- data/test/bmff/box/test_pixel_aspect_ratio.rb +28 -0
- data/test/bmff/box/test_progressive_download_info.rb +36 -0
- data/test/bmff/box/test_sample_auxiliary_information_offsets.rb +94 -0
- data/test/bmff/box/test_sample_auxiliary_information_sizes.rb +70 -0
- data/test/bmff/box/test_sample_dependency_type.rb +70 -0
- data/test/bmff/box/test_sample_description.rb +355 -0
- data/test/bmff/box/test_sample_size.rb +61 -0
- data/test/bmff/box/test_sample_table.rb +26 -0
- data/test/bmff/box/test_sample_to_chunk.rb +39 -0
- data/test/bmff/box/test_shadow_sync_sample.rb +36 -0
- data/test/bmff/box/test_sound_media_header.rb +32 -0
- data/test/bmff/box/test_sub_sample_information.rb +90 -0
- data/test/bmff/box/test_sync_sample.rb +34 -0
- data/test/bmff/box/test_text_meta_data_sample_entry.rb +49 -0
- data/test/bmff/box/test_time_to_sample.rb +36 -0
- data/test/bmff/box/test_track.rb +26 -0
- data/test/bmff/box/test_track_extends.rb +38 -0
- data/test/bmff/box/test_track_fragment.rb +26 -0
- data/test/bmff/box/test_track_fragment_base_media_decode_time.rb +52 -0
- data/test/bmff/box/test_track_fragment_header.rb +200 -0
- data/test/bmff/box/test_track_fragment_random_access.rb +96 -0
- data/test/bmff/box/test_track_group.rb +26 -0
- data/test/bmff/box/test_track_group_type.rb +30 -0
- data/test/bmff/box/test_track_header.rb +118 -0
- data/test/bmff/box/test_track_reference.rb +26 -0
- data/test/bmff/box/test_track_reference_type.rb +100 -0
- data/test/bmff/box/test_track_run.rb +282 -0
- data/test/bmff/box/test_track_selection.rb +33 -0
- data/test/bmff/box/test_uri.rb +30 -0
- data/test/bmff/box/test_uri_init.rb +32 -0
- data/test/bmff/box/test_uri_meta_sample_entry.rb +74 -0
- data/test/bmff/box/test_user_data.rb +26 -0
- data/test/bmff/box/test_video_media_header.rb +34 -0
- data/test/bmff/box/test_visual_sample_entry.rb +95 -0
- data/test/bmff/box/test_xml_meta_data_sample_entry.rb +51 -0
- data/test/bmff/test_binary_accessor.rb +805 -0
- data/test/bmff/test_file_container.rb +58 -0
- data/test/minitest_helper.rb +7 -0
- metadata +323 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleAuxiliaryInformationOffsets < MiniTest::Unit::TestCase
|
9
|
+
def test_parse_v0_flags_0
|
10
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
11
|
+
io.extend(BMFF::BinaryAccessor)
|
12
|
+
io.write_uint32(0)
|
13
|
+
io.write_ascii("saio")
|
14
|
+
io.write_uint8(0) # version
|
15
|
+
io.write_uint24(0) # flags
|
16
|
+
io.write_uint32(3) # entry_count
|
17
|
+
3.times do |i|
|
18
|
+
io.write_uint32(i) # offset
|
19
|
+
end
|
20
|
+
size = io.pos
|
21
|
+
io.pos = 0
|
22
|
+
io.write_uint32(size)
|
23
|
+
io.pos = 0
|
24
|
+
|
25
|
+
box = BMFF::Box.get_box(io, nil)
|
26
|
+
assert_instance_of(BMFF::Box::SampleAuxiliaryInformationOffsets, box)
|
27
|
+
assert_equal(size, box.actual_size)
|
28
|
+
assert_equal("saio", box.type)
|
29
|
+
assert_equal(0, box.version)
|
30
|
+
assert_equal(0, box.flags)
|
31
|
+
assert_nil(box.aux_info_type)
|
32
|
+
assert_nil(box.aux_info_type_parameter)
|
33
|
+
assert_equal(3, box.entry_count)
|
34
|
+
assert_equal([0, 1, 2], box.offsets)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse_v0_flags_1
|
38
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
39
|
+
io.extend(BMFF::BinaryAccessor)
|
40
|
+
io.write_uint32(0)
|
41
|
+
io.write_ascii("saio")
|
42
|
+
io.write_uint8(0) # version
|
43
|
+
io.write_uint24(1) # flags
|
44
|
+
io.write_uint32(1) # aux_info_type
|
45
|
+
io.write_uint32(2) # aux_info_type_parameter
|
46
|
+
io.write_uint32(3) # entry_count
|
47
|
+
3.times do |i|
|
48
|
+
io.write_uint32(i) # offset
|
49
|
+
end
|
50
|
+
size = io.pos
|
51
|
+
io.pos = 0
|
52
|
+
io.write_uint32(size)
|
53
|
+
io.pos = 0
|
54
|
+
|
55
|
+
box = BMFF::Box.get_box(io, nil)
|
56
|
+
assert_instance_of(BMFF::Box::SampleAuxiliaryInformationOffsets, box)
|
57
|
+
assert_equal(size, box.actual_size)
|
58
|
+
assert_equal("saio", box.type)
|
59
|
+
assert_equal(0, box.version)
|
60
|
+
assert_equal(1, box.flags)
|
61
|
+
assert_equal(1, box.aux_info_type)
|
62
|
+
assert_equal(2, box.aux_info_type_parameter)
|
63
|
+
assert_equal(3, box.entry_count)
|
64
|
+
assert_equal([0, 1, 2], box.offsets)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_parse_v1_flags_0
|
68
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
69
|
+
io.extend(BMFF::BinaryAccessor)
|
70
|
+
io.write_uint32(0)
|
71
|
+
io.write_ascii("saio")
|
72
|
+
io.write_uint8(1) # version
|
73
|
+
io.write_uint24(0) # flags
|
74
|
+
io.write_uint32(3) # entry_count
|
75
|
+
3.times do |i|
|
76
|
+
io.write_uint64(i) # offset
|
77
|
+
end
|
78
|
+
size = io.pos
|
79
|
+
io.pos = 0
|
80
|
+
io.write_uint32(size)
|
81
|
+
io.pos = 0
|
82
|
+
|
83
|
+
box = BMFF::Box.get_box(io, nil)
|
84
|
+
assert_instance_of(BMFF::Box::SampleAuxiliaryInformationOffsets, box)
|
85
|
+
assert_equal(size, box.actual_size)
|
86
|
+
assert_equal("saio", box.type)
|
87
|
+
assert_equal(1, box.version)
|
88
|
+
assert_equal(0, box.flags)
|
89
|
+
assert_nil(box.aux_info_type)
|
90
|
+
assert_nil(box.aux_info_type_parameter)
|
91
|
+
assert_equal(3, box.entry_count)
|
92
|
+
assert_equal([0, 1, 2], box.offsets)
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleAuxiliaryInformationSizes < MiniTest::Unit::TestCase
|
9
|
+
def test_parse_flags_0
|
10
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
11
|
+
io.extend(BMFF::BinaryAccessor)
|
12
|
+
io.write_uint32(0)
|
13
|
+
io.write_ascii("saiz")
|
14
|
+
io.write_uint8(0) # version
|
15
|
+
io.write_uint24(0) # flags
|
16
|
+
io.write_uint8(0) # default_sample_info_size
|
17
|
+
io.write_uint32(3) # sample_count
|
18
|
+
3.times do |i|
|
19
|
+
io.write_uint8(i) # sample_info_size
|
20
|
+
end
|
21
|
+
size = io.pos
|
22
|
+
io.pos = 0
|
23
|
+
io.write_uint32(size)
|
24
|
+
io.pos = 0
|
25
|
+
|
26
|
+
box = BMFF::Box.get_box(io, nil)
|
27
|
+
assert_instance_of(BMFF::Box::SampleAuxiliaryInformationSizes, box)
|
28
|
+
assert_equal(size, box.actual_size)
|
29
|
+
assert_equal("saiz", box.type)
|
30
|
+
assert_equal(0, box.version)
|
31
|
+
assert_equal(0, box.flags)
|
32
|
+
assert_nil(box.aux_info_type)
|
33
|
+
assert_nil(box.aux_info_type_parameter)
|
34
|
+
assert_equal(0, box.default_sample_info_size)
|
35
|
+
assert_equal(3, box.sample_count)
|
36
|
+
assert_equal([0, 1, 2], box.sample_info_size)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parse_flags_1
|
40
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
41
|
+
io.extend(BMFF::BinaryAccessor)
|
42
|
+
io.write_uint32(0)
|
43
|
+
io.write_ascii("saiz")
|
44
|
+
io.write_uint8(0) # version
|
45
|
+
io.write_uint24(1) # flags
|
46
|
+
io.write_uint32(1) # aux_info_type
|
47
|
+
io.write_uint32(2) # aux_info_type_parameter
|
48
|
+
io.write_uint8(0) # default_sample_info_size
|
49
|
+
io.write_uint32(3) # sample_count
|
50
|
+
3.times do |i|
|
51
|
+
io.write_uint8(i) # sample_info_size
|
52
|
+
end
|
53
|
+
size = io.pos
|
54
|
+
io.pos = 0
|
55
|
+
io.write_uint32(size)
|
56
|
+
io.pos = 0
|
57
|
+
|
58
|
+
box = BMFF::Box.get_box(io, nil)
|
59
|
+
assert_instance_of(BMFF::Box::SampleAuxiliaryInformationSizes, box)
|
60
|
+
assert_equal(size, box.actual_size)
|
61
|
+
assert_equal("saiz", box.type)
|
62
|
+
assert_equal(0, box.version)
|
63
|
+
assert_equal(1, box.flags)
|
64
|
+
assert_equal(1, box.aux_info_type)
|
65
|
+
assert_equal(2, box.aux_info_type_parameter)
|
66
|
+
assert_equal(0, box.default_sample_info_size)
|
67
|
+
assert_equal(3, box.sample_count)
|
68
|
+
assert_equal([0, 1, 2], box.sample_info_size)
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleDependencyType < MiniTest::Unit::TestCase
|
9
|
+
class DummyBox
|
10
|
+
attr_accessor :box
|
11
|
+
def find(type)
|
12
|
+
@box
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_sample_size(count = 1)
|
17
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
18
|
+
io.extend(BMFF::BinaryAccessor)
|
19
|
+
io.write_uint32(0)
|
20
|
+
io.write_ascii("stsz")
|
21
|
+
io.write_uint8(0) # version
|
22
|
+
io.write_uint24(0) # flags
|
23
|
+
io.write_uint32(0) # sample_size
|
24
|
+
io.write_uint32(count) # sample_count
|
25
|
+
count.times do |i|
|
26
|
+
io.write_uint32(i) # entry_size
|
27
|
+
end
|
28
|
+
size = io.pos
|
29
|
+
io.pos = 0
|
30
|
+
io.write_uint32(size)
|
31
|
+
io.pos = 0
|
32
|
+
|
33
|
+
box = BMFF::Box.get_box(io, nil)
|
34
|
+
dummy = DummyBox.new
|
35
|
+
dummy.box = box
|
36
|
+
dummy
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parse
|
40
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
41
|
+
io.extend(BMFF::BinaryAccessor)
|
42
|
+
io.write_uint32(0)
|
43
|
+
io.write_ascii("sdtp")
|
44
|
+
io.write_uint8(0) # version
|
45
|
+
io.write_uint24(0) # flags
|
46
|
+
# is_leading (0), sample_depends_on (1), sample_is_depended_on (2), sample_has_redundancy (3)
|
47
|
+
io.write_uint8(27)
|
48
|
+
# is_leading (1), sample_depends_on (2), sample_is_depended_on (3), sample_has_redundancy (0)
|
49
|
+
io.write_uint8(108)
|
50
|
+
# is_leading (2), sample_depends_on (3), sample_is_depended_on (0), sample_has_redundancy (1)
|
51
|
+
io.write_uint8(177)
|
52
|
+
# is_leading (3), sample_depends_on (0), sample_is_depended_on (1), sample_has_redundancy (2)
|
53
|
+
io.write_uint8(198)
|
54
|
+
size = io.pos
|
55
|
+
io.pos = 0
|
56
|
+
io.write_uint32(size)
|
57
|
+
io.pos = 0
|
58
|
+
|
59
|
+
box = BMFF::Box.get_box(io, get_sample_size(4))
|
60
|
+
assert_instance_of(BMFF::Box::SampleDependencyType, box)
|
61
|
+
assert_equal(size, box.actual_size)
|
62
|
+
assert_equal("sdtp", box.type)
|
63
|
+
assert_equal(0, box.version)
|
64
|
+
assert_equal(0, box.flags)
|
65
|
+
assert_equal([0, 1, 2, 3], box.is_leading)
|
66
|
+
assert_equal([1, 2, 3, 0], box.sample_depends_on)
|
67
|
+
assert_equal([2, 3, 0, 1], box.sample_is_depended_on)
|
68
|
+
assert_equal([3, 0, 1, 2], box.sample_has_redundancy)
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleDescription < MiniTest::Unit::TestCase
|
9
|
+
class DummyBox
|
10
|
+
attr_accessor :parent, :box
|
11
|
+
def find(type)
|
12
|
+
@box
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_handler(handler_type)
|
17
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
18
|
+
io.extend(BMFF::BinaryAccessor)
|
19
|
+
io.write_uint32(0)
|
20
|
+
io.write_ascii("hdlr")
|
21
|
+
io.write_uint8(0) # version
|
22
|
+
io.write_uint24(0) # flags
|
23
|
+
io.write_uint32(0) # pre_defined
|
24
|
+
io.write_ascii(handler_type) # handler_type
|
25
|
+
io.write_uint32(0) # reserved1
|
26
|
+
io.write_uint32(0) # reserved1
|
27
|
+
io.write_uint32(0) # reserved1
|
28
|
+
io.write_null_terminated_string("bmff test") # name
|
29
|
+
size = io.pos
|
30
|
+
io.pos = 0
|
31
|
+
io.write_uint32(size)
|
32
|
+
io.pos = 0
|
33
|
+
|
34
|
+
box = BMFF::Box.get_box(io, nil)
|
35
|
+
d1 = DummyBox.new
|
36
|
+
d2 = DummyBox.new
|
37
|
+
d3 = DummyBox.new
|
38
|
+
d1.box = box
|
39
|
+
d2.parent = d1
|
40
|
+
d3.parent = d2
|
41
|
+
d3
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_parse_soun
|
45
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
46
|
+
io.extend(BMFF::BinaryAccessor)
|
47
|
+
io.write_uint32(0)
|
48
|
+
io.write_ascii("stsd")
|
49
|
+
io.write_uint8(0) # version
|
50
|
+
io.write_uint24(0) # flags
|
51
|
+
io.write_uint32(1) # entry_count
|
52
|
+
# entry
|
53
|
+
io.write_uint32(36)
|
54
|
+
io.write_ascii("mp4a")
|
55
|
+
io.write_uint8(0) # reserved1
|
56
|
+
io.write_uint8(0) # reserved1
|
57
|
+
io.write_uint8(0) # reserved1
|
58
|
+
io.write_uint8(0) # reserved1
|
59
|
+
io.write_uint8(0) # reserved1
|
60
|
+
io.write_uint8(0) # reserved1
|
61
|
+
io.write_uint16(1) # data_reference_index
|
62
|
+
io.write_uint32(0) # reserved2
|
63
|
+
io.write_uint32(0) # reserved2
|
64
|
+
io.write_uint16(2) # channelcount
|
65
|
+
io.write_uint16(16) # samplesize
|
66
|
+
io.write_uint16(0) # pre_defined
|
67
|
+
io.write_uint16(0) # reserved3
|
68
|
+
io.write_uint32(2890137600) # samplerate
|
69
|
+
size = io.pos
|
70
|
+
io.pos = 0
|
71
|
+
io.write_uint32(size)
|
72
|
+
io.pos = 0
|
73
|
+
|
74
|
+
box = BMFF::Box.get_box(io, get_handler("soun"))
|
75
|
+
assert_instance_of(BMFF::Box::SampleDescription, box)
|
76
|
+
assert_equal(size, box.actual_size)
|
77
|
+
assert_equal("stsd", box.type)
|
78
|
+
assert_equal(0, box.version)
|
79
|
+
assert_equal(0, box.flags)
|
80
|
+
assert_equal(1, box.entry_count)
|
81
|
+
assert_equal(1, box.children.count)
|
82
|
+
|
83
|
+
assert_instance_of(BMFF::Box::AudioSampleEntry, box.children.first)
|
84
|
+
assert_equal(36, box.children.first.actual_size)
|
85
|
+
assert_equal("mp4a", box.children.first.type)
|
86
|
+
assert_equal([0, 0, 0, 0, 0, 0], box.children.first.reserved1)
|
87
|
+
assert_equal(1, box.children.first.data_reference_index)
|
88
|
+
assert_equal([0, 0], box.children.first.reserved2)
|
89
|
+
assert_equal(2, box.children.first.channelcount)
|
90
|
+
assert_equal(16, box.children.first.samplesize)
|
91
|
+
assert_equal(0, box.children.first.pre_defined)
|
92
|
+
assert_equal(0, box.children.first.reserved3)
|
93
|
+
assert_equal(2890137600, box.children.first.samplerate)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_parse_vide
|
97
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
98
|
+
io.extend(BMFF::BinaryAccessor)
|
99
|
+
io.write_uint32(0)
|
100
|
+
io.write_ascii("stsd")
|
101
|
+
io.write_uint8(0) # version
|
102
|
+
io.write_uint24(0) # flags
|
103
|
+
io.write_uint32(1) # entry_count
|
104
|
+
# entry
|
105
|
+
io.write_uint32(142)
|
106
|
+
io.write_ascii("mp4v")
|
107
|
+
io.write_uint8(0) # reserved1
|
108
|
+
io.write_uint8(0) # reserved1
|
109
|
+
io.write_uint8(0) # reserved1
|
110
|
+
io.write_uint8(0) # reserved1
|
111
|
+
io.write_uint8(0) # reserved1
|
112
|
+
io.write_uint8(0) # reserved1
|
113
|
+
io.write_uint16(1) # data_reference_index
|
114
|
+
io.write_uint16(0) # pre_defined1
|
115
|
+
io.write_uint16(0) # reserved2
|
116
|
+
io.write_uint32(0) # pre_defined2
|
117
|
+
io.write_uint32(0) # pre_defined2
|
118
|
+
io.write_uint32(0) # pre_defined2
|
119
|
+
io.write_uint16(320) # width
|
120
|
+
io.write_uint16(180) # height
|
121
|
+
io.write_uint32(4718592) # horizresolution
|
122
|
+
io.write_uint32(4718592) # vertresolution
|
123
|
+
io.write_uint32(0) # reserved3
|
124
|
+
io.write_uint16(1) # frame_count
|
125
|
+
io.write_byte("\x04") # compressorname (size)
|
126
|
+
io.write_ascii("bmff") # compressorname
|
127
|
+
io.write_byte("\x00" * 27) # compressorname (padding)
|
128
|
+
io.write_uint16(24) # depth
|
129
|
+
io.write_int16(-1) # pre_defined3
|
130
|
+
# clean_aperture_box
|
131
|
+
io.write_uint32(40)
|
132
|
+
io.write_ascii("clap")
|
133
|
+
io.write_uint32(160) # clean_aperture_width_n
|
134
|
+
io.write_uint32(161) # clean_aperture_width_d
|
135
|
+
io.write_uint32(90) # clean_aperture_height_n
|
136
|
+
io.write_uint32(91) # clean_aperture_height_d
|
137
|
+
io.write_uint32(320) # horiz_off_n
|
138
|
+
io.write_uint32(321) # horiz_off_d
|
139
|
+
io.write_uint32(180) # vert_off_n
|
140
|
+
io.write_uint32(181) # vert_off_d
|
141
|
+
# pixel_aspect_ratio_box
|
142
|
+
io.write_uint32(16)
|
143
|
+
io.write_ascii("pasp")
|
144
|
+
io.write_uint32(16) # h_spacing
|
145
|
+
io.write_uint32(9) # v_spacing
|
146
|
+
size = io.pos
|
147
|
+
io.pos = 0
|
148
|
+
io.write_uint32(size)
|
149
|
+
io.pos = 0
|
150
|
+
|
151
|
+
box = BMFF::Box.get_box(io, get_handler("vide"))
|
152
|
+
assert_instance_of(BMFF::Box::SampleDescription, box)
|
153
|
+
assert_equal(size, box.actual_size)
|
154
|
+
assert_equal("stsd", box.type)
|
155
|
+
assert_equal(0, box.version)
|
156
|
+
assert_equal(0, box.flags)
|
157
|
+
assert_equal(1, box.entry_count)
|
158
|
+
assert_equal(1, box.children.count)
|
159
|
+
|
160
|
+
assert_instance_of(BMFF::Box::VisualSampleEntry, box.children.first)
|
161
|
+
assert_equal(142, box.children.first.actual_size)
|
162
|
+
assert_equal("mp4v", box.children.first.type)
|
163
|
+
assert_equal([0, 0, 0, 0, 0, 0], box.children.first.reserved1)
|
164
|
+
assert_equal(1, box.children.first.data_reference_index)
|
165
|
+
assert_equal(0, box.children.first.pre_defined1)
|
166
|
+
assert_equal(0, box.children.first.reserved2)
|
167
|
+
assert_equal([0, 0, 0], box.children.first.pre_defined2)
|
168
|
+
assert_equal(320, box.children.first.width)
|
169
|
+
assert_equal(180, box.children.first.height)
|
170
|
+
assert_equal(4718592, box.children.first.horizresolution)
|
171
|
+
assert_equal(4718592, box.children.first.vertresolution)
|
172
|
+
assert_equal(0, box.children.first.reserved3)
|
173
|
+
assert_equal(1, box.children.first.frame_count)
|
174
|
+
assert_equal("bmff", box.children.first.compressorname)
|
175
|
+
assert_equal(24, box.children.first.depth)
|
176
|
+
assert_equal(-1, box.children.first.pre_defined3)
|
177
|
+
|
178
|
+
assert_instance_of(BMFF::Box::CleanAperture, box.children.first.clean_aperture_box)
|
179
|
+
assert_equal(40, box.children.first.clean_aperture_box.actual_size)
|
180
|
+
assert_equal("clap", box.children.first.clean_aperture_box.type)
|
181
|
+
assert_equal(160, box.children.first.clean_aperture_box.clean_aperture_width_n)
|
182
|
+
assert_equal(161, box.children.first.clean_aperture_box.clean_aperture_width_d)
|
183
|
+
assert_equal(90, box.children.first.clean_aperture_box.clean_aperture_height_n)
|
184
|
+
assert_equal(91, box.children.first.clean_aperture_box.clean_aperture_height_d)
|
185
|
+
assert_equal(320, box.children.first.clean_aperture_box.horiz_off_n)
|
186
|
+
assert_equal(321, box.children.first.clean_aperture_box.horiz_off_d)
|
187
|
+
assert_equal(180, box.children.first.clean_aperture_box.vert_off_n)
|
188
|
+
assert_equal(181, box.children.first.clean_aperture_box.vert_off_d)
|
189
|
+
|
190
|
+
assert_instance_of(BMFF::Box::PixelAspectRatio, box.children.first.pixel_aspect_ratio_box)
|
191
|
+
assert_equal(16, box.children.first.pixel_aspect_ratio_box.actual_size)
|
192
|
+
assert_equal("pasp", box.children.first.pixel_aspect_ratio_box.type)
|
193
|
+
assert_equal(16, box.children.first.pixel_aspect_ratio_box.h_spacing)
|
194
|
+
assert_equal(9, box.children.first.pixel_aspect_ratio_box.v_spacing)
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
def test_parse_hint
|
199
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
200
|
+
io.extend(BMFF::BinaryAccessor)
|
201
|
+
io.write_uint32(0)
|
202
|
+
io.write_ascii("stsd")
|
203
|
+
io.write_uint8(0) # version
|
204
|
+
io.write_uint24(0) # flags
|
205
|
+
io.write_uint32(1) # entry_count
|
206
|
+
# entry
|
207
|
+
io.write_uint32(20)
|
208
|
+
io.write_ascii("hint")
|
209
|
+
io.write_uint8(0) # reserved1
|
210
|
+
io.write_uint8(0) # reserved1
|
211
|
+
io.write_uint8(0) # reserved1
|
212
|
+
io.write_uint8(0) # reserved1
|
213
|
+
io.write_uint8(0) # reserved1
|
214
|
+
io.write_uint8(0) # reserved1
|
215
|
+
io.write_uint16(1) # data_reference_index
|
216
|
+
io.write_uint8(0) # data
|
217
|
+
io.write_uint8(1) # data
|
218
|
+
io.write_uint8(2) # data
|
219
|
+
io.write_uint8(3) # data
|
220
|
+
size = io.pos
|
221
|
+
io.pos = 0
|
222
|
+
io.write_uint32(size)
|
223
|
+
io.pos = 0
|
224
|
+
|
225
|
+
box = BMFF::Box.get_box(io, get_handler("hint"))
|
226
|
+
assert_instance_of(BMFF::Box::SampleDescription, box)
|
227
|
+
assert_equal(size, box.actual_size)
|
228
|
+
assert_equal("stsd", box.type)
|
229
|
+
assert_equal(0, box.version)
|
230
|
+
assert_equal(0, box.flags)
|
231
|
+
assert_equal(1, box.entry_count)
|
232
|
+
assert_equal(1, box.children.count)
|
233
|
+
|
234
|
+
assert_instance_of(BMFF::Box::HintSampleEntry, box.children.first)
|
235
|
+
assert_equal(20, box.children.first.actual_size)
|
236
|
+
assert_equal("hint", box.children.first.type)
|
237
|
+
assert_equal([0, 0, 0, 0, 0, 0], box.children.first.reserved1)
|
238
|
+
assert_equal(1, box.children.first.data_reference_index)
|
239
|
+
assert_equal([0, 1, 2, 3], box.children.first.data)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_parse_meta_metx
|
243
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
244
|
+
io.extend(BMFF::BinaryAccessor)
|
245
|
+
io.write_uint32(0)
|
246
|
+
io.write_ascii("stsd")
|
247
|
+
io.write_uint8(0) # version
|
248
|
+
io.write_uint24(0) # flags
|
249
|
+
io.write_uint32(1) # entry_count
|
250
|
+
# entry
|
251
|
+
io.write_uint32(81)
|
252
|
+
io.write_ascii("metx")
|
253
|
+
io.write_uint8(0) # reserved1
|
254
|
+
io.write_uint8(0) # reserved1
|
255
|
+
io.write_uint8(0) # reserved1
|
256
|
+
io.write_uint8(0) # reserved1
|
257
|
+
io.write_uint8(0) # reserved1
|
258
|
+
io.write_uint8(0) # reserved1
|
259
|
+
io.write_uint16(0) # data_reference_index
|
260
|
+
io.write_null_terminated_string("application/zip") # content_encoding
|
261
|
+
io.write_null_terminated_string("NS") # namespace
|
262
|
+
io.write_null_terminated_string("http://example.com/schema") # schema_location
|
263
|
+
# bit_rate_box
|
264
|
+
io.write_uint32(20)
|
265
|
+
io.write_ascii("btrt")
|
266
|
+
io.write_uint32(65535) # buffer_size_db
|
267
|
+
io.write_uint32(1000000) # max_bitrate
|
268
|
+
io.write_uint32(500000) # avg_bitrate
|
269
|
+
size = io.pos
|
270
|
+
io.pos = 0
|
271
|
+
io.write_uint32(size)
|
272
|
+
io.pos = 0
|
273
|
+
|
274
|
+
box = BMFF::Box.get_box(io, get_handler("meta"))
|
275
|
+
assert_instance_of(BMFF::Box::SampleDescription, box)
|
276
|
+
assert_equal(size, box.actual_size)
|
277
|
+
assert_equal("stsd", box.type)
|
278
|
+
assert_equal(0, box.version)
|
279
|
+
assert_equal(0, box.flags)
|
280
|
+
assert_equal(1, box.entry_count)
|
281
|
+
assert_equal(1, box.children.count)
|
282
|
+
|
283
|
+
assert_instance_of(BMFF::Box::XMLMetaDataSampleEntry, box.children.first)
|
284
|
+
assert_equal(81, box.children.first.actual_size)
|
285
|
+
assert_equal("metx", box.children.first.type)
|
286
|
+
assert_equal([0, 0, 0, 0, 0, 0], box.children.first.reserved1)
|
287
|
+
assert_equal(0, box.children.first.data_reference_index)
|
288
|
+
assert_equal("application/zip", box.children.first.content_encoding)
|
289
|
+
assert_equal("NS", box.children.first.namespace)
|
290
|
+
assert_equal("http://example.com/schema", box.children.first.schema_location)
|
291
|
+
|
292
|
+
assert_instance_of(BMFF::Box::BitRate, box.children.first.bit_rate_box)
|
293
|
+
assert_equal(20, box.children.first.bit_rate_box.actual_size)
|
294
|
+
assert_equal("btrt", box.children.first.bit_rate_box.type)
|
295
|
+
assert_equal(65535, box.children.first.bit_rate_box.buffer_size_db)
|
296
|
+
assert_equal(1000000, box.children.first.bit_rate_box.max_bitrate)
|
297
|
+
assert_equal(500000, box.children.first.bit_rate_box.avg_bitrate)
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_parse_meta_mett
|
301
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
302
|
+
io.extend(BMFF::BinaryAccessor)
|
303
|
+
io.write_uint32(0)
|
304
|
+
io.write_ascii("stsd")
|
305
|
+
io.write_uint8(0) # version
|
306
|
+
io.write_uint24(0) # flags
|
307
|
+
io.write_uint32(1) # entry_count
|
308
|
+
# entry
|
309
|
+
io.write_uint32(62)
|
310
|
+
io.write_ascii("mett")
|
311
|
+
io.write_uint8(0) # reserved1
|
312
|
+
io.write_uint8(0) # reserved1
|
313
|
+
io.write_uint8(0) # reserved1
|
314
|
+
io.write_uint8(0) # reserved1
|
315
|
+
io.write_uint8(0) # reserved1
|
316
|
+
io.write_uint8(0) # reserved1
|
317
|
+
io.write_uint16(0) # data_reference_index
|
318
|
+
io.write_null_terminated_string("application/zip") # content_encoding
|
319
|
+
io.write_null_terminated_string("text/html") # mime_format
|
320
|
+
# bit_rate_box
|
321
|
+
io.write_uint32(20)
|
322
|
+
io.write_ascii("btrt")
|
323
|
+
io.write_uint32(65535) # buffer_size_db
|
324
|
+
io.write_uint32(1000000) # max_bitrate
|
325
|
+
io.write_uint32(500000) # avg_bitrate
|
326
|
+
size = io.pos
|
327
|
+
io.pos = 0
|
328
|
+
io.write_uint32(size)
|
329
|
+
io.pos = 0
|
330
|
+
|
331
|
+
box = BMFF::Box.get_box(io, get_handler("meta"))
|
332
|
+
assert_instance_of(BMFF::Box::SampleDescription, box)
|
333
|
+
assert_equal(size, box.actual_size)
|
334
|
+
assert_equal("stsd", box.type)
|
335
|
+
assert_equal(0, box.version)
|
336
|
+
assert_equal(0, box.flags)
|
337
|
+
assert_equal(1, box.entry_count)
|
338
|
+
assert_equal(1, box.children.count)
|
339
|
+
|
340
|
+
assert_instance_of(BMFF::Box::TextMetaDataSampleEntry, box.children.first)
|
341
|
+
assert_equal(62, box.children.first.actual_size)
|
342
|
+
assert_equal("mett", box.children.first.type)
|
343
|
+
assert_equal([0, 0, 0, 0, 0, 0], box.children.first.reserved1)
|
344
|
+
assert_equal(0, box.children.first.data_reference_index)
|
345
|
+
assert_equal("application/zip", box.children.first.content_encoding)
|
346
|
+
assert_equal("text/html", box.children.first.mime_format)
|
347
|
+
|
348
|
+
assert_instance_of(BMFF::Box::BitRate, box.children.first.bit_rate_box)
|
349
|
+
assert_equal(20, box.children.first.bit_rate_box.actual_size)
|
350
|
+
assert_equal("btrt", box.children.first.bit_rate_box.type)
|
351
|
+
assert_equal(65535, box.children.first.bit_rate_box.buffer_size_db)
|
352
|
+
assert_equal(1000000, box.children.first.bit_rate_box.max_bitrate)
|
353
|
+
assert_equal(500000, box.children.first.bit_rate_box.avg_bitrate)
|
354
|
+
end
|
355
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleSize < MiniTest::Unit::TestCase
|
9
|
+
def test_parse_size_0
|
10
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
11
|
+
io.extend(BMFF::BinaryAccessor)
|
12
|
+
io.write_uint32(0)
|
13
|
+
io.write_ascii("stsz")
|
14
|
+
io.write_uint8(0) # version
|
15
|
+
io.write_uint24(0) # flags
|
16
|
+
io.write_uint32(0) # sample_size
|
17
|
+
io.write_uint32(3) # sample_count
|
18
|
+
3.times do |i|
|
19
|
+
io.write_uint32(i) # entry_size
|
20
|
+
end
|
21
|
+
size = io.pos
|
22
|
+
io.pos = 0
|
23
|
+
io.write_uint32(size)
|
24
|
+
io.pos = 0
|
25
|
+
|
26
|
+
box = BMFF::Box.get_box(io, nil)
|
27
|
+
assert_instance_of(BMFF::Box::SampleSize, box)
|
28
|
+
assert_equal(size, box.actual_size)
|
29
|
+
assert_equal("stsz", box.type)
|
30
|
+
assert_equal(0, box.version)
|
31
|
+
assert_equal(0, box.flags)
|
32
|
+
assert_equal(0, box.sample_size)
|
33
|
+
assert_equal(3, box.sample_count)
|
34
|
+
assert_equal([0, 1, 2], box.entry_size)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse_size_1
|
38
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
39
|
+
io.extend(BMFF::BinaryAccessor)
|
40
|
+
io.write_uint32(0)
|
41
|
+
io.write_ascii("stsz")
|
42
|
+
io.write_uint8(0) # version
|
43
|
+
io.write_uint24(0) # flags
|
44
|
+
io.write_uint32(1) # sample_size
|
45
|
+
io.write_uint32(3) # sample_count
|
46
|
+
size = io.pos
|
47
|
+
io.pos = 0
|
48
|
+
io.write_uint32(size)
|
49
|
+
io.pos = 0
|
50
|
+
|
51
|
+
box = BMFF::Box.get_box(io, nil)
|
52
|
+
assert_instance_of(BMFF::Box::SampleSize, box)
|
53
|
+
assert_equal(size, box.actual_size)
|
54
|
+
assert_equal("stsz", box.type)
|
55
|
+
assert_equal(0, box.version)
|
56
|
+
assert_equal(0, box.flags)
|
57
|
+
assert_equal(1, box.sample_size)
|
58
|
+
assert_equal(3, box.sample_count)
|
59
|
+
assert_equal([], box.entry_size)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
|
3
|
+
|
4
|
+
require_relative '../../minitest_helper'
|
5
|
+
require 'bmff/box'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestBMFFBoxSampleTable < MiniTest::Unit::TestCase
|
9
|
+
def test_parse
|
10
|
+
io = StringIO.new("", "r+:ascii-8bit")
|
11
|
+
io.extend(BMFF::BinaryAccessor)
|
12
|
+
io.write_uint32(0)
|
13
|
+
io.write_ascii("stbl")
|
14
|
+
size = io.pos
|
15
|
+
io.pos = 0
|
16
|
+
io.write_uint32(size)
|
17
|
+
io.pos = 0
|
18
|
+
|
19
|
+
box = BMFF::Box.get_box(io, nil)
|
20
|
+
assert_instance_of(BMFF::Box::SampleTable, box)
|
21
|
+
assert_equal(size, box.actual_size)
|
22
|
+
assert_equal("stbl", box.type)
|
23
|
+
assert_equal([], box.children)
|
24
|
+
assert(box.container?)
|
25
|
+
end
|
26
|
+
end
|