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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49394510e191185e3be1f3560ca182a103b9446225a1163294f2db6a912ae76
4
- data.tar.gz: 4f52d761857020a0957711528ad4d10ee885c74745897fa14a5e69292abf0cc2
3
+ metadata.gz: d8bdd6daa59e43bbe6033562b804d3b1b9685c6e2aa5ef3f8d527c74516e1f6c
4
+ data.tar.gz: d6035f0b3c819085ffd23c4988e48145976ba1f98547d16589b2a4b4aa3e7aa7
5
5
  SHA512:
6
- metadata.gz: 829bd488d021cb0db5ce2b718aa661bdf3d4f86a55e55808c8279367e955d35b2bdccdd2bdf805ff736cef6d49f8c0f425c1ec65c0d7f07ada2db684581d4c1f
7
- data.tar.gz: ed76f04c157a865de03df0d614d0d353b53e1e9c9b0a164ac6b2a6612a358643ae210b00fd92b91fec6cefd8c8c71e6ff559e63df3343b13ce161175425dbd3a
6
+ metadata.gz: 1a2f6243d295589972c63e45b719f19a5761c872103c32bfaacaef9cee9b85551c18ddaaf3c4095567c358958e7b7bf78800fc3e5a8e6c9f774eab383dc3160c
7
+ data.tar.gz: 73ba4f1099ccb4c490b50a8f531be843679159a6417980b2a61b905724905cf6b7e884127b66096e2237982dc6743e7f057bea0062472c1779e4d754dd5388ff
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.0
2
+ * Add support for `codecs` in moov_parser for video metadata
3
+
1
4
  ## 1.1.0
2
5
  * Add support for `frame_rate` in moov_parser
3
6
 
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gem 'ruby-debug-ide'
4
4
  gem 'debase'
5
5
  gem 'solargraph', group: :development
6
+ gem 'pry', group: :development
6
7
 
7
8
  # Gem dependencies specified in the gemspec
8
9
  gemspec
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -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
@@ -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: 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 parse_sample_atom(decoder, atom_tree)
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
@@ -13,6 +13,8 @@ module FormatParser
13
13
  # Type of the file (e.g :mp3)
14
14
  attr_accessor :format
15
15
 
16
+ attr_accessor :codecs
17
+
16
18
  # Duration of the media object (be it audio or video) in seconds,
17
19
  # as a Float
18
20
  attr_accessor :media_duration_seconds
@@ -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.1.0
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-01 00:00:00.000000000 Z
12
+ date: 2022-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks