mediainfo 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,14 +1,19 @@
1
+ v0.6.0 XML Output
2
+ - v0.7.25 of the Mediainfo CLI is now required, as the Mediainfo class'
3
+ parsing implementation is now based on parsing XML output. REXML will
4
+ be used by default, but Hpricot and Nokogiri are also supported.
5
+
1
6
  v0.5.1 Packaging Fix
2
7
  - Gemspec was referencing a missing file
3
8
  - Behold: THREE DIGIT VERSION NUMBER. Serious business now!
4
9
 
5
- v0.5 Raw, Son
10
+ v0.5.0 Raw, Son
6
11
  - You can now initialize an instance from raw CLI output
7
12
 
8
- v0.4 Mediainfo Respects Your Existing Customs
13
+ v0.4.0 Mediainfo Respects Your Existing Customs
9
14
  - Define String#shell_escape only if it is not already defined
10
15
 
11
- v0.3 Mediainfo Is High Class
16
+ v0.3.0 Mediainfo Is High Class
12
17
  - Class instead of instance-level customization of mediainfo binary path.
13
18
  Set Mediainfo.path = /path/to/binary if mediainfo is not in your shell
14
19
  path.
@@ -18,7 +23,7 @@ v0.3 Mediainfo Is High Class
18
23
  Mediainfo::ExecutionError instead of RuntimeError if the system command
19
24
  exits with anything other than 0.
20
25
 
21
- v0.2 Escape from the Shell
26
+ v0.2.0 Escape from the Shell
22
27
  - Added proper escaping for funky filenames. Thanks to Peter Vandenberk!
23
28
 
24
- v0.1 Initial Release
29
+ v0.1.0 Initial Release
data/README.markdown CHANGED
@@ -2,37 +2,37 @@
2
2
 
3
3
  Mediainfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.net).
4
4
 
5
+ ## Installation
6
+
7
+ $ gem install mediainfo -s http://gemcutter.org
8
+
5
9
  ## Usage
6
10
 
7
11
  info = Mediainfo.new "/path/to/file"
8
12
 
9
13
  That will issue the system call to `mediainfo` and parse the output.
10
- From there, you can call numerous methods to get a variety of information
11
- about a file. Some attributes may be present for some files where others
12
- are not.
14
+ You can specify an alternate path if necessary:
15
+
16
+ Mediainfo.path = "/opt/local/bin/mediainfo"
17
+
18
+ Once you've got an instance setup, you can call numerous methods to get
19
+ a variety of information about a file. Some attributes may be present
20
+ for some files where others are not, but any supported attribute
21
+ should at least return `nil`.
13
22
 
14
23
  For a list of all possible attributes supported:
15
24
 
16
25
  Mediainfo.supported_attributes
17
26
 
18
- In addition to the stock arguments provided by parsing `mediainfo` output,
19
- some convenience methods and added behavior is added.
20
-
21
- Mediainfo is inspired by RVideo::Inspector, part of the rvideo gem.
22
- The rvideo inspector is based on output from ffmpeg which is not
23
- intended to be machine parseable. I spent a little while chasing
24
- the ffmpeg development team, and decided finally that perhaps other
25
- tools were better. As such, some of the API for Mediainfo is straight
26
- from RVideo::Inspector. Some is not. Just saying.
27
-
28
27
  ## Requirements
29
28
 
30
- This library is compatible with:
29
+ This requires at least the following version of the Mediainfo CLI:
31
30
 
32
31
  MediaInfo Command line,
33
- MediaInfoLib - v0.7.11
32
+ MediaInfoLib - v0.7.25
34
33
 
35
- to the extent that is documented in the tests.
34
+ Previous versions of this gem(<= 0.5.1) worked against v0.7.11, which did not
35
+ generate XML output, and is no longer supported.
36
36
 
37
37
  ## Contributors
38
38
 
data/Rakefile CHANGED
@@ -1,37 +1,60 @@
1
- require "rake/testtask"
2
- load "Rakefile.cloud" if File.exist? "Rakefile.cloud"
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.test_files = FileList["test/*_test.rb"]
7
- t.verbose = true
8
- end
1
+ require "rubygems"
2
+ require "echoe"
9
3
 
10
- task :default => :test
11
-
12
- namespace :mediainfo do
13
- task :fixture do
14
- unless file = ENV["file"]
15
- puts "Usage: rake mediainfo:fixture file=/path/to/file"
16
- exit
17
- end
18
- fixture = File.expand_path "./test/fixtures/#{File.basename file}.txt"
19
- system "mediainfo #{file} > #{fixture}"
20
- if File.exist? fixture
21
- puts "Generated fixture #{fixture}."
22
- else
23
- puts "Error generating fixture. #{fixture} not created."
24
- end
4
+ class Echoe
5
+ def honor_gitignore!
6
+ self.ignore_pattern += \
7
+ Dir["**/.gitignore"].inject([]) do |pattern,gitignore|
8
+ pattern.concat \
9
+ File.readlines(gitignore).
10
+ map { |line| line.strip }.
11
+ reject { |line| "" == line }.
12
+ map { |glob|
13
+ d = File.dirname(gitignore)
14
+ d == "." ? glob : File.join(d, glob)
15
+ }
16
+ end.flatten.uniq
25
17
  end
26
18
  end
27
19
 
28
- require "rubygems"
29
- require "echoe"
30
-
31
20
  Echoe.new "mediainfo" do |p|
32
21
  p.description = "Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)"
33
22
  p.author = "Seth Thomas Rasmussen"
34
23
  p.email = "sethrasmussen@gmail.com"
35
24
  p.url = "http://greatseth.com"
36
25
  p.ignore_pattern = %w( test/**/* )
26
+ p.honor_gitignore!
27
+ end
28
+
29
+ task :rexml do
30
+ ENV.delete "MEDIAINFO_XML_PARSER"
31
+ Rake::Task[:test].invoke
32
+ end
33
+
34
+ task :hpricot do
35
+ ENV["MEDIAINFO_XML_PARSER"] = "hpricot"
36
+ Rake::Task[:test].invoke
37
+ end
38
+
39
+ task :nokogiri do
40
+ ENV["MEDIAINFO_XML_PARSER"] = "nokogiri"
41
+ Rake::Task[:test].invoke
42
+ end
43
+
44
+ # TODO This doesn't work.
45
+ task :all => [:rexml, :nokogiri, :hpricot]
46
+
47
+
48
+ task :fixture do
49
+ unless file = ENV["FILE"]
50
+ puts "Usage: rake mediainfo:fixture file=/path/to/file"
51
+ exit
52
+ end
53
+ fixture = File.expand_path "./test/fixtures/#{File.basename file}.xml"
54
+ system "mediainfo #{file} --Output=XML > #{fixture}"
55
+ if File.exist? fixture
56
+ puts "Generated fixture #{fixture}."
57
+ else
58
+ puts "Error generating fixture. #{fixture} not created."
59
+ end
37
60
  end
data/lib/mediainfo.rb CHANGED
@@ -33,7 +33,7 @@ require "mediainfo/attr_readers"
33
33
  class Mediainfo
34
34
  extend AttrReaders
35
35
 
36
- SECTIONS = %w( Audio Video Image ) # and General
36
+ SECTIONS = %w( audio video image ) # and General
37
37
 
38
38
  ### GENERAL
39
39
 
@@ -48,7 +48,7 @@ class Mediainfo
48
48
  mediainfo_attr_reader :writing_application
49
49
  mediainfo_attr_reader :writing_library
50
50
 
51
- def size; File.size(@full_filename); end
51
+ def size; File.size(@full_filename) if @full_filename; end
52
52
 
53
53
  mediainfo_date_reader :mastered_date
54
54
  mediainfo_date_reader :tagged_date
@@ -58,8 +58,6 @@ class Mediainfo
58
58
 
59
59
  mediainfo_section_query :video
60
60
 
61
- # XXX this breaks from RVideo::Inspector which returns
62
- # something like "#0.1" instead of "1"
63
61
  mediainfo_attr_reader :video_stream_id, "ID"
64
62
 
65
63
  mediainfo_duration_reader :video_duration
@@ -92,6 +90,9 @@ class Mediainfo
92
90
  # Format settings, QPel : No
93
91
  # Format settings, GMC : No warppoints
94
92
  # mediainfo_attr_reader :video_format_settings_qpel, "Format settings, QPel"
93
+ mediainfo_attr_reader :video_color_primaries
94
+ mediainfo_attr_reader :video_transfer_characteristics
95
+ mediainfo_attr_reader :video_matrix_coefficients
95
96
 
96
97
  mediainfo_attr_reader :video_codec_id, "Codec ID"
97
98
  mediainfo_attr_reader :video_codec_info, "Codec ID/Info"
@@ -100,6 +101,14 @@ class Mediainfo
100
101
  def fps; video_frame_rate[/[\d.]+/].to_f if video?; end
101
102
  alias_method :framerate, :fps
102
103
 
104
+ mediainfo_attr_reader :video_minimum_frame_rate
105
+ def min_fps; video_minimum_frame_rate[/[\d.]+/].to_f if video?; end
106
+ alias_method :min_framerate, :min_fps
107
+
108
+ mediainfo_attr_reader :video_maximum_frame_rate
109
+ def max_fps; video_maximum_frame_rate[/[\d.]+/].to_f if video?; end
110
+ alias_method :max_framerate, :max_fps
111
+
103
112
  mediainfo_attr_reader :video_frame_rate_mode
104
113
 
105
114
  mediainfo_attr_reader :video_display_aspect_ratio
@@ -121,8 +130,6 @@ class Mediainfo
121
130
 
122
131
  mediainfo_section_query :audio
123
132
 
124
- # XXX this breaks from RVideo::Inspector which returns
125
- # something like "#0.1" instead of "1"
126
133
  mediainfo_attr_reader :audio_stream_id, "ID"
127
134
 
128
135
  mediainfo_duration_reader :audio_duration
@@ -155,10 +162,9 @@ class Mediainfo
155
162
  mediainfo_attr_reader :audio_format_settings_sign, "Format settings, Sign"
156
163
  mediainfo_attr_reader :audio_codec_id, "Codec ID"
157
164
  mediainfo_attr_reader :audio_codec_info, "Codec ID/Info"
165
+ mediainfo_attr_reader :audio_codec_id_hint
158
166
  mediainfo_attr_reader :audio_channel_positions
159
167
 
160
- # XXX this breaks from RVideo::Inspector which returns
161
- # strings like "mono" or "stereo" for this method.
162
168
  mediainfo_int_reader :audio_channels, "Channel(s)"
163
169
  def stereo?; 2 == audio_channels; end
164
170
  def mono?; 1 == audio_channels; end
@@ -180,81 +186,150 @@ class Mediainfo
180
186
  attr_reader :raw_response, :parsed_response,
181
187
  :full_filename, :filename, :path, :escaped_full_filename
182
188
 
189
+ ###
190
+
191
+ class Error < StandardError; end
192
+ class ExecutionError < Error; end
193
+ class IncompatibleVersionError < Error; end
194
+
195
+ def self.version
196
+ @version ||= `#{path} --Version`[/v([\d.]+)/, 1]
197
+ end
198
+
199
+ ###
200
+
183
201
  def initialize(full_filename = nil)
202
+ if mediainfo_version < "0.7.25"
203
+ raise IncompatibleVersionError,
204
+ "Your version of mediainfo, #{mediainfo_version}, " +
205
+ "is not compatible with this gem. >= 0.7.25 required."
206
+ end
207
+
184
208
  if full_filename
185
209
  @full_filename = File.expand_path full_filename
186
210
  @path = File.dirname @full_filename
187
211
  @filename = File.basename @full_filename
188
-
212
+
189
213
  raise ArgumentError, "need a path to a video file, got nil" unless @full_filename
190
214
  raise ArgumentError, "need a path to a video file, #{@full_filename} does not exist" unless File.exist? @full_filename
191
-
215
+
192
216
  @escaped_full_filename = @full_filename.shell_escape
193
-
217
+
194
218
  self.raw_response = mediainfo!
195
219
  end
196
220
  end
197
-
198
- def raw_response=(mediainfo_cli_output)
199
- @raw_response = mediainfo_cli_output
221
+
222
+ def raw_response=(response)
223
+ raise ArgumentError, "raw response is nil" if response.nil?
224
+ @raw_response = response
200
225
  parse!
201
226
  @raw_response
202
227
  end
203
228
 
204
- class << self; attr_accessor :path; end
229
+ class << self
230
+ attr_accessor :path
231
+
232
+ def load_xml_parser!(parser = xml_parser)
233
+ begin
234
+ gem parser
235
+ require parser
236
+ rescue Gem::LoadError => e
237
+ raise Gem::LoadError,
238
+ "your specified XML parser, #{parser.inspect}, could not be loaded: #{e}"
239
+ end
240
+ end
241
+
242
+ attr_reader :xml_parser
243
+ def xml_parser=(parser)
244
+ load_xml_parser! parser
245
+ @xml_parser = parser
246
+ end
247
+ end
248
+
249
+ unless ENV["MEDIAINFO_XML_PARSER"].to_s.strip.empty?
250
+ self.xml_parser = ENV["MEDIAINFO_XML_PARSER"]
251
+ end
252
+
205
253
  def path; self.class.path; end
254
+ def xml_parser; self.class.xml_parser; end
206
255
 
207
256
  def self.default_mediainfo_path!; self.path = "mediainfo"; end
208
257
  default_mediainfo_path! unless path
209
258
 
210
259
  def mediainfo_version
211
- `#{path} --Version`[/v([\d.]+)/, 1]
260
+ self.class.version
212
261
  end
213
262
 
214
263
  attr_reader :last_command
215
264
 
216
- class Error < StandardError; end
217
- class ExecutionError < Error; end
218
-
219
265
  def inspect
220
266
  super.sub /@raw_response=".+?", @/, %{@raw_response="...", @}
221
267
  end
222
268
 
223
269
  private
224
270
  def mediainfo!
225
- # for bash, see: http://www.faqs.org/docs/bashman/bashref_12.html
226
- # but appears to be working for other shells: sh, zsh, ksh, dash
227
- @last_command = "#{path} #{@escaped_full_filename}"
228
- run_last_command!
271
+ @last_command = "#{path} #{@escaped_full_filename} --Output=XML"
272
+ run_command!
229
273
  end
230
274
 
231
- def run_last_command!
232
- raw_response = `#{@last_command}`
275
+ def run_command!
276
+ raw_response = `#{@last_command} 2>&1`
233
277
  unless $? == 0
234
- raise ExecutionError, "Execution of `#{@last_command}` failed: #{raw_response.inspect}"
278
+ raise ExecutionError,
279
+ "Execution of `#{@last_command}` failed: #{raw_response.inspect}"
235
280
  end
236
281
  raw_response
237
282
  end
238
283
 
239
284
  def parse!
285
+ if xml_parser
286
+ self.class.load_xml_parser!
287
+ else
288
+ require "rexml/document"
289
+ end
290
+
240
291
  @parsed_response = {}
241
- subsection = nil
242
292
 
243
- @raw_response.to_s.split("\n").map { |x| x.strip }.each do |line|
244
- next if line.empty? || line == "General"
245
-
246
- if SECTIONS.include? line
247
- subsection = line
248
- @parsed_response[subsection] = {}
249
- next
250
- end
251
-
252
- bucket = @parsed_response
253
- bucket = bucket[subsection] if subsection
254
-
255
- key, value = line.split(":", 2).map { |x| x.strip }
256
-
257
- bucket[key] = value
293
+ case xml_parser
294
+ when "nokogiri"
295
+ Nokogiri::XML(@raw_response).xpath("//track").each { |t|
296
+ bucket = bucket_for t['type']
297
+
298
+ t.xpath("*").each do |c|
299
+ bucket[key_for(c)] = c.content.strip
300
+ end
301
+ }
302
+ when "hpricot"
303
+ Hpricot::XML(@raw_response).search("track").each { |t|
304
+ bucket = bucket_for t['type']
305
+
306
+ t.children.select { |n| n.is_a? Hpricot::Elem }.each do |c|
307
+ bucket[key_for(c)] = c.inner_html.strip
308
+ end
309
+ }
310
+ else
311
+ REXML::Document.new(@raw_response).elements.each("/Mediainfo/File/track") { |t|
312
+ bucket = bucket_for t.attributes['type']
313
+
314
+ t.children.select { |n| n.is_a? REXML::Element }.each do |c|
315
+ bucket[key_for(c)] = c.text.strip
316
+ end
317
+ }
318
+ end
319
+ end
320
+
321
+ def key_for(attribute_node)
322
+ attribute_node.name.downcase.gsub(/_+/, "_").gsub(/_s(\W|$)/, "s").strip
323
+ end
324
+
325
+ def bucket_for(section)
326
+ section = section.downcase if section
327
+
328
+ if section == "general"
329
+ @parsed_response
330
+ else
331
+ @parsed_response[section] ||= {}
332
+ @parsed_response[section]
258
333
  end
259
334
  end
260
335
  end
@@ -1,5 +1,5 @@
1
- require "rubygems"
2
- require "active_support" # TODO selective includes once they are released
1
+ require "time"
2
+ require "mediainfo/string"
3
3
 
4
4
  class Mediainfo
5
5
  module AttrReaders
@@ -10,17 +10,19 @@ module AttrReaders
10
10
  def mediainfo_attr_reader(name, mediainfo_key = nil)
11
11
  supported_attributes << name
12
12
  attr_name = "#{name}_before_type_cast"
13
+ mediainfo_key = mediainfo_key.gsub(/\W+/, "_").downcase if mediainfo_key
14
+
13
15
  define_method attr_name do
14
16
  if v = instance_variable_get("@#{attr_name}")
15
17
  v
16
18
  else
17
19
  v = if md = name.to_s.match(/^(#{SECTIONS.map { |x| x.underscore } * "|"})_(.+)$/)
18
- k = mediainfo_key ? mediainfo_key : md[2].humanize.capitalize
19
- if subsection = @parsed_response[md[1].capitalize]
20
+ k = mediainfo_key ? mediainfo_key : md[2]
21
+ if subsection = @parsed_response[md[1]]
20
22
  subsection[k]
21
23
  end
22
24
  else
23
- k = mediainfo_key ? mediainfo_key : name.to_s.humanize.capitalize
25
+ k = mediainfo_key ? mediainfo_key : name.to_s
24
26
  @parsed_response[k]
25
27
  end
26
28
 
@@ -70,7 +72,7 @@ module AttrReaders
70
72
  end
71
73
 
72
74
  def mediainfo_section_query(name)
73
- define_method("#{name}?") { @parsed_response.key? name.to_s.capitalize }
75
+ define_method("#{name}?") { @parsed_response.key? name.to_s }
74
76
  end
75
77
  end
76
78
  end
@@ -6,4 +6,14 @@ class String
6
6
  # but appears to be working for other shells: sh, zsh, ksh, dash
7
7
  "$'#{gsub(/\\|'/) { |c| "\\#{c}" }}'"
8
8
  end unless method_defined?(:shell_escape)
9
+
10
+ # stolen from active_support/inflector
11
+ # TODO require "active_support/core_ext/string/inflections" when 3.0 is released
12
+ def underscore
13
+ gsub(/::/, '/').
14
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
15
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
16
+ tr("-", "_").
17
+ downcase
18
+ end unless method_defined?(:underscore)
9
19
  end
data/mediainfo.gemspec CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mediainfo}
5
- s.version = "0.5.1"
5
+ s.version = "0.6.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Seth Thomas Rasmussen"]
9
- s.date = %q{2009-11-19}
9
+ s.date = %q{2009-11-25}
10
10
  s.description = %q{Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)}
11
11
  s.email = %q{sethrasmussen@gmail.com}
12
12
  s.extra_rdoc_files = ["LICENSE", "README.markdown", "lib/mediainfo.rb", "lib/mediainfo/attr_readers.rb", "lib/mediainfo/string.rb"]
13
- s.files = ["Changelog", "LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/mediainfo.rb", "lib/mediainfo/attr_readers.rb", "lib/mediainfo/string.rb", "mediainfo.gemspec", "test/mediainfo_awaywego_encoded_test.rb", "test/mediainfo_awaywego_test.rb", "test/mediainfo_dinner_test.rb", "test/mediainfo_hats_test.rb", "test/mediainfo_string_test.rb", "test/mediainfo_test.rb", "test/mediainfo_vimeo_test.rb", "test/mediainfo_vimeoimage_test.rb", "test/test_helper.rb"]
13
+ s.files = ["Changelog", "LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/mediainfo.rb", "lib/mediainfo/attr_readers.rb", "lib/mediainfo/string.rb", "mediainfo.gemspec", "test/mediainfo_awaywego_test.rb", "test/mediainfo_broken_embraces_test.rb", "test/mediainfo_dinner_test.rb", "test/mediainfo_hats_test.rb", "test/mediainfo_omen_image_test.rb", "test/mediainfo_string_test.rb", "test/mediainfo_test.rb", "test/mediainfo_vimeo_test.rb", "test/test_helper.rb"]
14
14
  s.homepage = %q{http://greatseth.com}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mediainfo", "--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{mediainfo}
18
18
  s.rubygems_version = %q{1.3.5}
19
19
  s.summary = %q{Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)}
20
- s.test_files = ["test/mediainfo_awaywego_encoded_test.rb", "test/mediainfo_awaywego_test.rb", "test/mediainfo_dinner_test.rb", "test/mediainfo_hats_test.rb", "test/mediainfo_string_test.rb", "test/mediainfo_test.rb", "test/mediainfo_vimeo_test.rb", "test/mediainfo_vimeoimage_test.rb", "test/test_helper.rb"]
20
+ s.test_files = ["test/mediainfo_awaywego_test.rb", "test/mediainfo_broken_embraces_test.rb", "test/mediainfo_dinner_test.rb", "test/mediainfo_hats_test.rb", "test/mediainfo_omen_image_test.rb", "test/mediainfo_string_test.rb", "test/mediainfo_test.rb", "test/mediainfo_vimeo_test.rb", "test/test_helper.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -129,8 +129,8 @@ class MediainfoAwaywegoTest < ActiveSupport::TestCase
129
129
  end
130
130
 
131
131
  test "video Display aspect ratio" do
132
- assert_equal "2.25", @info.video_display_aspect_ratio
133
- assert_equal "2.25", @info.display_aspect_ratio
132
+ assert_equal "2.25:1", @info.video_display_aspect_ratio
133
+ assert_equal "2.25:1", @info.display_aspect_ratio
134
134
  end
135
135
 
136
136
  test "video frame rate" do
@@ -173,12 +173,26 @@ class MediainfoAwaywegoTest < ActiveSupport::TestCase
173
173
 
174
174
  test "video encoded date" do
175
175
  assert_kind_of Time, @info.video_encoded_date
176
- # assert_equal "UTC 2009-03-30 19:57:50", @info.video_encoded_date
177
176
  end
178
177
 
179
178
  test "video tagged date" do
180
179
  assert_kind_of Time, @info.video_tagged_date
181
- # assert_equal "UTC 2009-03-30 19:57:57", @info.video_tagged_date
180
+ end
181
+
182
+ test "video color primaries" do
183
+ assert_equal \
184
+ "BT.709-5, BT.1361, IEC 61966-2-4, SMPTE RP177",
185
+ @info.video_color_primaries
186
+ end
187
+
188
+ test "video transfer characteristics" do
189
+ assert_equal "BT.709-5, BT.1361", @info.video_transfer_characteristics
190
+ end
191
+
192
+ test "video matrix coefficients" do
193
+ assert_equal \
194
+ "BT.709-5, BT.1361, IEC 61966-2-4 709, SMPTE RP177",
195
+ @info.video_matrix_coefficients
182
196
  end
183
197
 
184
198
  ### AUDIO
@@ -261,12 +275,10 @@ class MediainfoAwaywegoTest < ActiveSupport::TestCase
261
275
 
262
276
  test "audio encoded date" do
263
277
  assert_kind_of Time, @info.audio_encoded_date
264
- # assert_equal "UTC 2009-03-30 19:57:50", @info.audio_encoded_date
265
278
  end
266
279
 
267
280
  test "audio tagged date" do
268
281
  assert_kind_of Time, @info.audio_tagged_date
269
- # assert_equal "UTC 2009-03-30 19:57:57", @info.audio_tagged_date
270
282
  end
271
283
 
272
284
  ### IMAGE
@@ -1,9 +1,9 @@
1
1
  require "test_helper"
2
2
  require "mediainfo_test_helper"
3
3
 
4
- class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
4
+ class MediainfoBrokenEmbracesTest < ActiveSupport::TestCase
5
5
  def setup
6
- @info = mediainfo_mock "AwayWeGo_24fps_253_15000_1920x840.mov"
6
+ @info = mediainfo_mock "Broken Embraces_510_780_576x432.mp4"
7
7
  end
8
8
 
9
9
  ### GENERAL
@@ -17,26 +17,26 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  test "format" do
20
- assert_equal "MPEG-PS", @info.format
20
+ assert_equal "MPEG-4", @info.format
21
21
  end
22
22
 
23
23
  test "format profile" do
24
- assert_nil @info.format_profile
24
+ assert_equal "Base Media", @info.format_profile
25
25
  end
26
26
 
27
27
  test "codec id" do
28
- assert_nil @info.codec_id
28
+ assert_equal "isom", @info.codec_id
29
29
  end
30
30
 
31
31
  mediainfo_test_size
32
32
 
33
33
  test "duration" do
34
- assert_equal 36224, @info.duration
35
- assert_equal "36s 224ms", @info.duration_before_type_cast
34
+ assert_equal 106000, @info.duration
35
+ assert_equal "1mn 46s", @info.duration_before_type_cast
36
36
  end
37
37
 
38
38
  test "overall bitrate" do
39
- assert_equal "17.3 Mbps", @info.overall_bit_rate
39
+ assert_equal "911 Kbps", @info.overall_bit_rate
40
40
  end
41
41
 
42
42
  test "encoded date" do
@@ -48,7 +48,7 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
48
48
  end
49
49
 
50
50
  test "writing application" do
51
- assert_nil @info.writing_application
51
+ assert_equal "Lavf52.39.0", @info.writing_application
52
52
  end
53
53
 
54
54
  test "writing library" do
@@ -58,138 +58,136 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
58
58
  ### VIDEO
59
59
 
60
60
  test "video stream id" do
61
- assert_equal "224 (0xE0)", @info.video_stream_id
61
+ assert_equal "1", @info.video_stream_id
62
62
  end
63
63
 
64
64
  test "video Format" do
65
- assert_equal "MPEG Video", @info.video_format
65
+ assert_equal "AVC", @info.video_format
66
66
  end
67
67
 
68
68
  test "video format version" do
69
- assert_equal "Version 2", @info.video_format_version
69
+ assert_nil @info.video_format_version
70
70
  end
71
71
 
72
72
  test "video format settings Matrix" do
73
- assert_equal "Default", @info.video_format_settings_matrix
73
+ assert_nil @info.video_format_settings_matrix
74
74
  end
75
75
 
76
76
  test "video format profile" do
77
- assert_nil @info.video_format_profile
77
+ assert_equal "High@L3.0", @info.video_format_profile
78
78
  end
79
79
 
80
80
  test "video format settings CABAC" do
81
- assert_nil @info.video_format_settings_cabac
81
+ assert_equal "Yes", @info.video_format_settings_cabac
82
82
  end
83
83
 
84
84
  test "video format settings ReFrames" do
85
- assert_nil @info.video_format_settings_reframes
85
+ assert_equal "4 frames", @info.video_format_settings_reframes
86
86
  end
87
87
 
88
88
  test "video Codec ID" do
89
- assert_nil @info.video_codec_id
89
+ assert_equal "avc1", @info.video_codec_id
90
90
  end
91
91
 
92
92
  test "video codec info" do
93
- assert_nil @info.video_codec_info
93
+ assert_equal "Advanced Video Coding", @info.video_codec_info
94
94
  end
95
95
 
96
96
  test "video Duration" do
97
- assert_equal 36202, @info.video_duration
98
- assert_equal "36s 202ms", @info.video_duration_before_type_cast
97
+ assert_equal 106000, @info.video_duration
98
+ assert_equal "1mn 46s", @info.video_duration_before_type_cast
99
99
  end
100
100
 
101
101
  test "video bit rate mode" do
102
- assert_equal "Constant", @info.video_bit_rate_mode
103
- assert !@info.vbr?
104
- assert @info.cbr?
102
+ assert_equal "Variable", @info.video_bit_rate_mode
103
+ assert @info.vbr?
104
+ assert !@info.cbr?
105
105
  end
106
106
 
107
107
  test "video Bit rate" do
108
- assert_equal "16.0 Mbps", @info.video_bit_rate
108
+ assert_equal "780 Kbps", @info.video_bit_rate
109
109
  end
110
110
 
111
111
  test "video nominal bit rate" do
112
- assert_equal "15.0 Mbps", @info.video_nominal_bit_rate
112
+ assert_nil @info.video_nominal_bit_rate
113
113
  end
114
114
 
115
115
  test "resolution" do
116
- assert_equal "1920x1080", @info.resolution
116
+ assert_equal "576x432", @info.resolution
117
117
  end
118
118
 
119
119
  test "video Width" do
120
- assert_equal 1920, @info.video_width
121
- assert_equal 1920, @info.width
120
+ assert_equal 576, @info.video_width
121
+ assert_equal 576, @info.width
122
122
  end
123
123
 
124
124
  test "video Height" do
125
- assert_equal 1080, @info.video_height
126
- assert_equal 1080, @info.height
125
+ assert_equal 432, @info.video_height
126
+ assert_equal 432, @info.height
127
127
  end
128
128
 
129
129
  test "video Display aspect ratio" do
130
- assert_equal "16/9", @info.video_display_aspect_ratio
131
- assert_equal "16/9", @info.display_aspect_ratio
130
+ assert_equal "4:3", @info.video_display_aspect_ratio
131
+ assert_equal "4:3", @info.display_aspect_ratio
132
132
  end
133
133
 
134
134
  test "video Frame rate" do
135
- assert_equal "29.970 fps", @info.video_frame_rate
136
- assert_equal 29.97, @info.fps
137
- assert_equal 29.97, @info.framerate
135
+ assert_equal "23.976 fps", @info.video_frame_rate
136
+ assert_equal 23.976, @info.fps
137
+ assert_equal 23.976, @info.framerate
138
138
  end
139
139
 
140
140
  test "video frame rate mode" do
141
- assert_nil @info.video_frame_rate_mode
141
+ assert_equal "Variable", @info.video_frame_rate_mode
142
142
  end
143
143
 
144
144
  test "video Resolution" do
145
- assert_nil @info.video_resolution
145
+ assert_equal 24, @info.video_resolution
146
146
  end
147
147
 
148
148
  test "video colorimetry" do
149
- assert_equal "4:2:2", @info.video_colorimetry
150
- assert_equal "4:2:2", @info.video_colorspace
149
+ assert_equal "4:2:0", @info.video_colorimetry
150
+ assert_equal "4:2:0", @info.video_colorspace
151
151
  end
152
152
 
153
153
  test "video Scan type" do
154
- assert_equal "Interlaced", @info.video_scan_type
155
- assert @info.interlaced?
156
- assert !@info.progressive?
154
+ assert_equal "Progressive", @info.video_scan_type
155
+ assert !@info.interlaced?
156
+ assert @info.progressive?
157
157
  end
158
158
 
159
159
  test "video scan order" do
160
- assert_equal "Bottom Field First", @info.video_scan_order
160
+ assert_nil @info.video_scan_order
161
161
  end
162
162
 
163
163
  test "video Bits/(Pixel*Frame)" do
164
- assert_equal "0.258", @info.video_bits_pixel_frame
164
+ assert_equal "0.131", @info.video_bits_pixel_frame
165
165
  end
166
166
 
167
167
  test "video Stream size" do
168
- assert_nil @info.video_stream_size
168
+ assert_equal "9.84 MiB (85%)", @info.video_stream_size
169
169
  end
170
170
 
171
171
  test "video encoded date" do
172
172
  assert_nil @info.video_encoded_date
173
- # assert_equal "UTC 2009-03-30 19:57:50", @info.video_encoded_date
174
173
  end
175
174
 
176
175
  test "video tagged date" do
177
176
  assert_nil @info.video_tagged_date
178
- # assert_equal "UTC 2009-03-30 19:57:57", @info.video_tagged_date
179
177
  end
180
178
 
181
179
  ### AUDIO
182
180
 
183
181
  test "audio stream id" do
184
- assert_equal "128 (0x80)", @info.audio_stream_id
182
+ assert_equal "2", @info.audio_stream_id
185
183
  end
186
184
 
187
185
  test "audio Format" do
188
- assert_equal "AC-3", @info.audio_format
186
+ assert_equal "AAC", @info.audio_format
189
187
  end
190
188
 
191
189
  test "audio format info" do
192
- assert_equal "Audio Coding 3", @info.audio_format_info
190
+ assert_equal "Advanced Audio Codec", @info.audio_format_info
193
191
  end
194
192
 
195
193
  test "audio Format settings, Endianness" do
@@ -201,7 +199,7 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
201
199
  end
202
200
 
203
201
  test "audio Codec ID" do
204
- assert_nil @info.audio_codec_id
202
+ assert_equal "40", @info.audio_codec_id
205
203
  end
206
204
 
207
205
  test "audio Codec ID/Info" do
@@ -209,16 +207,16 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
209
207
  end
210
208
 
211
209
  test "audio Duration" do
212
- assert_equal 36224, @info.audio_duration
213
- assert_equal "36s 224ms", @info.audio_duration_before_type_cast
210
+ assert_equal 106000, @info.audio_duration
211
+ assert_equal "1mn 46s", @info.audio_duration_before_type_cast
214
212
  end
215
213
 
216
214
  test "audio Bit rate mode" do
217
- assert_equal "Constant", @info.audio_bit_rate_mode
215
+ assert_equal "Variable", @info.audio_bit_rate_mode
218
216
  end
219
217
 
220
218
  test "audio Bit rate" do
221
- assert_equal "64.0 Kbps", @info.audio_bit_rate
219
+ assert_equal "128 Kbps", @info.audio_bit_rate
222
220
  end
223
221
 
224
222
  test "audio Channel(s)" do
@@ -238,17 +236,17 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
238
236
  end
239
237
 
240
238
  test "audio Sampling rate" do
241
- assert_equal 48000, @info.audio_sample_rate
242
- assert_equal 48000, @info.audio_sampling_rate
243
- assert_equal "48.0 KHz", @info.audio_sampling_rate_before_type_cast
239
+ assert_equal 44100, @info.audio_sample_rate
240
+ assert_equal 44100, @info.audio_sampling_rate
241
+ assert_equal "44.1 KHz", @info.audio_sampling_rate_before_type_cast
244
242
  end
245
243
 
246
244
  test "audio Resolution" do
247
- assert_nil @info.audio_resolution
245
+ assert_equal 16, @info.audio_resolution
248
246
  end
249
247
 
250
248
  test "audio Stream size" do
251
- assert_nil @info.audio_stream_size
249
+ assert_equal "1.62 MiB (14%)", @info.audio_stream_size
252
250
  end
253
251
 
254
252
  test "audio Interleave, duration" do
@@ -257,12 +255,10 @@ class MediainfoAwaywegoEncodedTest < ActiveSupport::TestCase
257
255
 
258
256
  test "audio encoded date" do
259
257
  assert_nil @info.audio_encoded_date
260
- # assert_equal "UTC 2009-03-30 19:57:50", @info.audio_encoded_date
261
258
  end
262
259
 
263
260
  test "audio tagged date" do
264
261
  assert_nil @info.audio_tagged_date
265
- # assert_equal "UTC 2009-03-30 19:57:57", @info.audio_tagged_date
266
262
  end
267
263
 
268
264
  ### IMAGE
@@ -74,7 +74,7 @@ class MediainfoDinnerTest < ActiveSupport::TestCase
74
74
  end
75
75
 
76
76
  test "video format settings Matrix" do
77
- assert_equal "Default", @info.video_format_settings_matrix
77
+ assert_equal "Default (H.263)", @info.video_format_settings_matrix
78
78
  end
79
79
 
80
80
  test "video format settings CABAC" do
@@ -131,6 +131,14 @@ class MediainfoDinnerTest < ActiveSupport::TestCase
131
131
  assert_equal "14.875 fps", @info.video_frame_rate
132
132
  assert_equal 14.875, @info.fps
133
133
  assert_equal 14.875, @info.framerate
134
+
135
+ assert_equal "2.370 fps", @info.video_minimum_frame_rate
136
+ assert_equal 2.370, @info.min_fps
137
+ assert_equal 2.370, @info.min_framerate
138
+
139
+ assert_equal "27.778 fps", @info.video_maximum_frame_rate
140
+ assert_equal 27.778, @info.max_fps
141
+ assert_equal 27.778, @info.max_framerate
134
142
  end
135
143
 
136
144
  test "video frame rate mode" do
@@ -209,7 +217,7 @@ class MediainfoDinnerTest < ActiveSupport::TestCase
209
217
  end
210
218
 
211
219
  test "audio Channel(s)" do
212
- assert_equal 11, @info.audio_channels
220
+ assert_equal 1, @info.audio_channels
213
221
  end
214
222
 
215
223
  test "audio channel positions" do
@@ -221,7 +229,7 @@ class MediainfoDinnerTest < ActiveSupport::TestCase
221
229
  end
222
230
 
223
231
  test "mono?" do
224
- assert !@info.mono?
232
+ assert @info.mono?
225
233
  end
226
234
 
227
235
  test "audio Sampling rate" do
@@ -1,9 +1,9 @@
1
1
  require "test_helper"
2
2
  require "mediainfo_test_helper"
3
3
 
4
- class MediainfoVimeoimageTest < ActiveSupport::TestCase
4
+ class MediainfoOmenImageTest < ActiveSupport::TestCase
5
5
  def setup
6
- @info = mediainfo_mock "vimeo.57652_55_500.jpg"
6
+ @info = mediainfo_mock "omen1976_464_0_480x336-6.jpg"
7
7
  end
8
8
 
9
9
  ### GENERAL
@@ -93,7 +93,7 @@ class MediainfoVimeoimageTest < ActiveSupport::TestCase
93
93
  end
94
94
 
95
95
  test "resolution" do
96
- assert_equal "640x360", @info.resolution
96
+ assert_equal "480x336", @info.resolution
97
97
  end
98
98
 
99
99
  test "video Width" do
@@ -219,13 +219,13 @@ class MediainfoVimeoimageTest < ActiveSupport::TestCase
219
219
  end
220
220
 
221
221
  test "image width" do
222
- assert_equal 640, @info.image_width
223
- assert_equal 640, @info.width
222
+ assert_equal 480, @info.image_width
223
+ assert_equal 480, @info.width
224
224
  end
225
225
 
226
226
  test "image height" do
227
- assert_equal 360, @info.image_height
228
- assert_equal 360, @info.height
227
+ assert_equal 336, @info.image_height
228
+ assert_equal 336, @info.height
229
229
  end
230
230
 
231
231
  test "image resolution" do
@@ -37,6 +37,8 @@ class MediainfoTest < ActiveSupport::TestCase
37
37
  :video_codec_id,
38
38
  :video_codec_info,
39
39
  :video_frame_rate,
40
+ :video_minimum_frame_rate,
41
+ :video_maximum_frame_rate,
40
42
  :video_frame_rate_mode,
41
43
  :video_display_aspect_ratio,
42
44
  :video_bits_pixel_frame,
@@ -44,6 +46,9 @@ class MediainfoTest < ActiveSupport::TestCase
44
46
  :video_height,
45
47
  :video_encoded_date,
46
48
  :video_tagged_date,
49
+ :video_color_primaries,
50
+ :video_transfer_characteristics,
51
+ :video_matrix_coefficients,
47
52
 
48
53
  ### AUDIO
49
54
 
@@ -60,6 +65,7 @@ class MediainfoTest < ActiveSupport::TestCase
60
65
  :audio_format_settings_endianness,
61
66
  :audio_format_settings_sign,
62
67
  :audio_codec_id,
68
+ :audio_codec_id_hint,
63
69
  :audio_codec_info,
64
70
  :audio_channel_positions,
65
71
  :audio_channels,
@@ -87,20 +93,26 @@ class MediainfoTest < ActiveSupport::TestCase
87
93
  end
88
94
 
89
95
  test "retains last system command generated" do
90
- m = Mediainfo.new "/dev/null"
91
- assert_equal "mediainfo $'/dev/null'", m.last_command
96
+ p = File.expand_path "./test/fixtures/dinner.3g2.xml"
97
+ m = Mediainfo.new p
98
+ assert_equal "mediainfo $'#{p}' --Output=XML", m.last_command
92
99
  end
93
100
 
94
101
  test "allows customization of path to mediainfo binary" do
95
- Mediainfo.any_instance.stubs(:run_last_command!)
102
+ Mediainfo.any_instance.stubs(:run_command!).returns("test")
96
103
 
97
104
  assert_equal "mediainfo", Mediainfo.path
98
105
 
106
+ m = Mediainfo.new "/dev/null"
107
+ assert_equal "mediainfo $'/dev/null' --Output=XML", m.last_command
108
+
109
+ Mediainfo.any_instance.stubs(:mediainfo_version).returns("0.7.25")
110
+
99
111
  Mediainfo.path = "/opt/local/bin/mediainfo"
100
112
  assert_equal "/opt/local/bin/mediainfo", Mediainfo.path
101
113
 
102
114
  m = Mediainfo.new "/dev/null"
103
- assert_equal "/opt/local/bin/mediainfo $'/dev/null'", m.last_command
115
+ assert_equal "/opt/local/bin/mediainfo $'/dev/null' --Output=XML", m.last_command
104
116
  end
105
117
 
106
118
  test "can be initialized with a raw response" do
@@ -109,4 +121,9 @@ class MediainfoTest < ActiveSupport::TestCase
109
121
  assert m.video?
110
122
  assert m.audio?
111
123
  end
124
+
125
+ test "cannot be initialized with version < 0.7.25" do
126
+ Mediainfo.any_instance.stubs(:mediainfo_version).returns("0.7.10")
127
+ assert_raises(Mediainfo::IncompatibleVersionError) { Mediainfo.new }
128
+ end
112
129
  end
@@ -39,6 +39,10 @@ class MediainfoVimeoTest < ActiveSupport::TestCase
39
39
  assert_equal "2 078 Kbps", @info.overall_bit_rate
40
40
  end
41
41
 
42
+ test "mastered date" do
43
+ assert_nil @info.encoded_date
44
+ end
45
+
42
46
  test "encoded date" do
43
47
  assert_nil @info.encoded_date
44
48
  end
@@ -57,8 +61,8 @@ class MediainfoVimeoTest < ActiveSupport::TestCase
57
61
 
58
62
  ### VIDEO
59
63
 
60
- test "video stream id" do
61
- assert_nil @info.video_stream_id
64
+ test "video stream id" do
65
+ assert_equal "0", @info.video_stream_id
62
66
  end
63
67
 
64
68
  test "video Format" do
@@ -123,8 +127,8 @@ class MediainfoVimeoTest < ActiveSupport::TestCase
123
127
  end
124
128
 
125
129
  test "video Display aspect ratio" do
126
- assert_equal "4/3", @info.video_display_aspect_ratio
127
- assert_equal "4/3", @info.display_aspect_ratio
130
+ assert_equal "4:3", @info.video_display_aspect_ratio
131
+ assert_equal "4:3", @info.display_aspect_ratio
128
132
  end
129
133
 
130
134
  test "video frame rate" do
@@ -179,6 +183,10 @@ class MediainfoVimeoTest < ActiveSupport::TestCase
179
183
  assert_nil @info.audio_format_info
180
184
  end
181
185
 
186
+ test "audio codec id hint" do
187
+ assert_equal "Intel", @info.audio_codec_id_hint
188
+ end
189
+
182
190
  test "audio Format settings, Endianness" do
183
191
  assert_nil @info.audio_format_settings_endianness
184
192
  end
@@ -192,7 +200,7 @@ class MediainfoVimeoTest < ActiveSupport::TestCase
192
200
  end
193
201
 
194
202
  test "audio Codec ID/Info" do
195
- assert_equal "Intel ADPCM", @info.audio_codec_info
203
+ assert_nil @info.audio_codec_info
196
204
  end
197
205
 
198
206
  test "audio Duration" do
data/test/test_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require "test/unit"
2
2
 
3
+ require "rubygems"
4
+ require "mocha"
5
+ begin; require "redgreen"; rescue LoadError; end
6
+
3
7
  module ActiveSupport
4
8
  class TestCase < Test::Unit::TestCase
5
9
  def self.test(desc, &block)
@@ -10,9 +14,6 @@ module ActiveSupport
10
14
  end
11
15
  end
12
16
 
13
- require "rubygems"
14
- require "mocha"
15
- begin; require "redgreen"; rescue LoadError; end
16
17
 
17
18
  $: << File.dirname(__FILE__) + "/../lib"
18
19
  require "mediainfo"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediainfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Thomas Rasmussen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 -05:00
12
+ date: 2009-11-25 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -69,12 +69,12 @@ signing_key:
69
69
  specification_version: 3
70
70
  summary: Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)
71
71
  test_files:
72
- - test/mediainfo_awaywego_encoded_test.rb
73
72
  - test/mediainfo_awaywego_test.rb
73
+ - test/mediainfo_broken_embraces_test.rb
74
74
  - test/mediainfo_dinner_test.rb
75
75
  - test/mediainfo_hats_test.rb
76
+ - test/mediainfo_omen_image_test.rb
76
77
  - test/mediainfo_string_test.rb
77
78
  - test/mediainfo_test.rb
78
79
  - test/mediainfo_vimeo_test.rb
79
- - test/mediainfo_vimeoimage_test.rb
80
80
  - test/test_helper.rb