Class: VideoDimensions::Backends::MediaInfo
- Defined in:
- lib/video_dimensions/backends/media_info.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bitrate ⇒ Object
- #codec ⇒ Object
- #dimensions ⇒ Object
- #duration ⇒ Object
- #framerate ⇒ Object
- #height ⇒ Object
-
#initialize(input) ⇒ MediaInfo
constructor
A new instance of MediaInfo.
- #width ⇒ Object
Constructor Details
#initialize(input) ⇒ MediaInfo
Returns a new instance of MediaInfo.
13 14 15 |
# File 'lib/video_dimensions/backends/media_info.rb', line 13 def initialize(input) @input = input end |
Class Method Details
.available? ⇒ Boolean
4 5 6 7 |
# File 'lib/video_dimensions/backends/media_info.rb', line 4 def self.available? `which #{binary} 2>&1 > /dev/null` $?.exitstatus == 0 end |
.binary ⇒ Object
9 10 11 |
# File 'lib/video_dimensions/backends/media_info.rb', line 9 def self.binary 'mediainfo' end |
Instance Method Details
#bitrate ⇒ Object
33 34 35 36 37 |
# File 'lib/video_dimensions/backends/media_info.rb', line 33 def bitrate output.match(/^Bit rate\s+: ([\d\s]+) Kbps$/) do |m| m[1].gsub(' ', '').to_i end end |
#codec ⇒ Object
39 40 41 42 43 |
# File 'lib/video_dimensions/backends/media_info.rb', line 39 def codec output.match(/^Codec ID\s+: (.+)$/) do |m| m[1] end end |
#dimensions ⇒ Object
17 18 19 |
# File 'lib/video_dimensions/backends/media_info.rb', line 17 def dimensions [width, height] if width && height end |
#duration ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/video_dimensions/backends/media_info.rb', line 45 def duration # MediaInfo only incudes the two longest durations in the ouptut (e.g., # 1h 5m; 5m 10s; 10s 15ms) output.match(/^Duration\s+:( \d+h)?( \d+mn)?( \d+s)?(?: \d+ms)?$/) do |m| # Map all of the captures to Integers, removing the time notation and # converting nils to 0, and use sprintf to include leading zeros sprintf("%02d:%02d:%02d", *m.captures.map(&:to_i)) end end |
#framerate ⇒ Object
55 56 57 58 59 |
# File 'lib/video_dimensions/backends/media_info.rb', line 55 def framerate output.match(/^Frame rate\s+: ([\d\.]+) fps$/) do |m| m[1].to_f end end |
#height ⇒ Object
27 28 29 30 31 |
# File 'lib/video_dimensions/backends/media_info.rb', line 27 def height output.match(/^Height\s+: ([\d\s]+) pixels$/) do |m| m[1].gsub(' ', '').to_i end end |
#width ⇒ Object
21 22 23 24 25 |
# File 'lib/video_dimensions/backends/media_info.rb', line 21 def width output.match(/^Width\s+: ([\d\s]+) pixels$/) do |m| m[1].gsub(' ', '').to_i end end |