Class: VideoDimensions::Backends::FFmpeg
- Defined in:
- lib/video_dimensions/backends/ffmpeg.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bitrate ⇒ Object
- #codec ⇒ Object
- #dimensions ⇒ Object
- #duration ⇒ Object
- #framerate ⇒ Object
- #height ⇒ Object
-
#initialize(input) ⇒ FFmpeg
constructor
A new instance of FFmpeg.
- #width ⇒ Object
Constructor Details
#initialize(input) ⇒ FFmpeg
Returns a new instance of FFmpeg.
13 14 15 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 13 def initialize(input) @input = input end |
Class Method Details
.available? ⇒ Boolean
4 5 6 7 |
# File 'lib/video_dimensions/backends/ffmpeg.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/ffmpeg.rb', line 9 def self.binary 'ffmpeg' end |
Instance Method Details
#bitrate ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 31 def bitrate # Video streams don't always surface their own bitrate, so we'll settle # for the "total" bitrate output.match(/^\s+Duration: .+bitrate: (\d+) kb\/s$/m) do |m| m[1].to_i end end |
#codec ⇒ Object
39 40 41 42 43 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 39 def codec output.match(/Stream .+ Video: (\w+)/m) do |m| m[1] end end |
#dimensions ⇒ Object
17 18 19 20 21 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 17 def dimensions output.match(/Stream .+ Video: .+ (\d+)x(\d+).*/) do |m| [m[1].to_i, m[2].to_i] end end |
#duration ⇒ Object
45 46 47 48 49 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 45 def duration output.match(/Duration: ([\d\:]+)/) do |m| m[1] end end |
#framerate ⇒ Object
51 52 53 54 55 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 51 def framerate output.match(/([\d\.]+) tbr/) do |m| m[1].to_f end end |
#height ⇒ Object
27 28 29 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 27 def height dimensions && dimensions[1] end |
#width ⇒ Object
23 24 25 |
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 23 def width dimensions && dimensions[0] end |