format_parser 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/moov_parser/decoder.rb +17 -0
- data/lib/parsers/moov_parser.rb +19 -3
- data/lib/video.rb +2 -0
- data/spec/parsers/moov_parser_spec.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8bdd6daa59e43bbe6033562b804d3b1b9685c6e2aa5ef3f8d527c74516e1f6c
|
4
|
+
data.tar.gz: d6035f0b3c819085ffd23c4988e48145976ba1f98547d16589b2a4b4aa3e7aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2f6243d295589972c63e45b719f19a5761c872103c32bfaacaef9cee9b85551c18ddaaf3c4095567c358958e7b7bf78800fc3e5a8e6c9f774eab383dc3160c
|
7
|
+
data.tar.gz: 73ba4f1099ccb4c490b50a8f531be843679159a6417980b2a61b905724905cf6b7e884127b66096e2237982dc6743e7f057bea0062472c1779e4d754dd5388ff
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -130,6 +130,23 @@ class FormatParser::MOOVParser::Decoder
|
|
130
130
|
stts
|
131
131
|
end
|
132
132
|
|
133
|
+
def parse_stsd_atom(io, _)
|
134
|
+
version = read_byte_value(io)
|
135
|
+
is_v1 = version == 1
|
136
|
+
stsd = {
|
137
|
+
version: version,
|
138
|
+
flags: read_bytes(io, 3),
|
139
|
+
number_of_entries: is_v1 ? read_64bit_uint(io) : read_32bit_uint(io),
|
140
|
+
codecs: []
|
141
|
+
}
|
142
|
+
stsd[:number_of_entries].times {
|
143
|
+
codec_length = read_32bit_uint(io)
|
144
|
+
stsd[:codecs] << read_bytes(io, 4)
|
145
|
+
io.seek(io.pos + codec_length - 8) # 8 bytes is the header length containing the codec length and the codec name that we just did read
|
146
|
+
}
|
147
|
+
stsd
|
148
|
+
end
|
149
|
+
|
133
150
|
def parse_mdhd_atom(io, _)
|
134
151
|
version = read_byte_value(io)
|
135
152
|
is_v1 = version == 1
|
data/lib/parsers/moov_parser.rb
CHANGED
@@ -64,14 +64,14 @@ class FormatParser::MOOVParser
|
|
64
64
|
intrinsics: atom_tree,
|
65
65
|
)
|
66
66
|
else
|
67
|
-
frame_rate = parse_sample_atom(decoder, atom_tree)&.truncate(2)
|
68
67
|
FormatParser::Video.new(
|
69
68
|
format: format_from_moov_type(file_type),
|
70
69
|
width_px: width,
|
71
70
|
height_px: height,
|
72
|
-
frame_rate:
|
71
|
+
frame_rate: parse_time_to_sample_atom(decoder, atom_tree)&.truncate(2),
|
73
72
|
media_duration_seconds: media_duration_s,
|
74
73
|
content_type: MP4_MIXED_MIME_TYPE,
|
74
|
+
codecs: parse_sample_description_atom(decoder, atom_tree),
|
75
75
|
intrinsics: atom_tree
|
76
76
|
)
|
77
77
|
end
|
@@ -119,7 +119,7 @@ class FormatParser::MOOVParser
|
|
119
119
|
|
120
120
|
# Sample information is found in the 'time-to-sample' stts atom.
|
121
121
|
# The media atom mdhd is needed too in order to get the movie timescale
|
122
|
-
def
|
122
|
+
def parse_time_to_sample_atom(decoder, atom_tree)
|
123
123
|
video_trak_atom = decoder.find_video_trak_atom(atom_tree)
|
124
124
|
|
125
125
|
stts = if video_trak_atom
|
@@ -147,5 +147,21 @@ class FormatParser::MOOVParser
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
+
def parse_sample_description_atom(decoder, atom_tree)
|
151
|
+
video_trak_atom = decoder.find_video_trak_atom(atom_tree)
|
152
|
+
|
153
|
+
stsd = if video_trak_atom
|
154
|
+
decoder.find_first_atom_by_path([video_trak_atom], 'trak', 'mdia', 'minf', 'stbl', 'stsd')
|
155
|
+
else
|
156
|
+
decoder.find_first_atom_by_path(atom_tree, 'moov', 'trak', 'mdia', 'minf', 'stbl', 'stsd')
|
157
|
+
end
|
158
|
+
|
159
|
+
if stsd
|
160
|
+
stsd.field_value(:codecs)
|
161
|
+
else
|
162
|
+
nil
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
150
166
|
FormatParser.register_parser new, natures: :video, formats: FTYP_MAP.values, priority: 1
|
151
167
|
end
|
data/lib/video.rb
CHANGED
@@ -94,6 +94,7 @@ describe FormatParser::MOOVParser do
|
|
94
94
|
expect(result.format).to eq(:mov)
|
95
95
|
expect(result.width_px).to eq(1920)
|
96
96
|
expect(result.height_px).to eq(1080)
|
97
|
+
expect(result.codecs).to eq(['apcn'])
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'parses an MP4 video file and provides the necessary metadata' do
|
@@ -107,6 +108,7 @@ describe FormatParser::MOOVParser do
|
|
107
108
|
expect(result.width_px).to eq(160)
|
108
109
|
expect(result.height_px).to eq(90)
|
109
110
|
expect(result.frame_rate).to eq(14.98)
|
111
|
+
expect(result.codecs).to eq(['avc1'])
|
110
112
|
end
|
111
113
|
|
112
114
|
it 'provides filename hints' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-04-
|
12
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|