Class: VideoDimensions::Backends::FFmpeg

Inherits:
Base
  • Object
show all
Defined in:
lib/video_dimensions/backends/ffmpeg.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

.binaryObject



9
10
11
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 9

def self.binary
  'ffmpeg'
end

Instance Method Details

#bitrateObject



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

#codecObject



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

#dimensionsObject



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

#durationObject



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

#framerateObject



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

#heightObject



27
28
29
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 27

def height
  dimensions && dimensions[1]
end

#widthObject



23
24
25
# File 'lib/video_dimensions/backends/ffmpeg.rb', line 23

def width
  dimensions && dimensions[0]
end