Class: Ffprober::Ffmpeg::Exec

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ffprober/ffmpeg/exec.rb

Constant Summary collapse

CHAPTER_SUPPORT =
T.let(Gem::Version.new('2.0.0'), Gem::Version)

Instance Method Summary collapse

Constructor Details

#initialize(finder = Ffprober::Ffmpeg::Finder.new) ⇒ Exec

Returns a new instance of Exec.



14
15
16
17
# File 'lib/ffprober/ffmpeg/exec.rb', line 14

def initialize(finder = Ffprober::Ffmpeg::Finder.new)
  @finder = finder
  @ffprobe_version_output = T.let(nil, T.nilable(String))
end

Instance Method Details

#ffprobe_optionsObject



36
37
38
39
40
41
42
43
# File 'lib/ffprober/ffmpeg/exec.rb', line 36

def ffprobe_options
  base_options = '-v quiet -print_format json -show_format'\
                 ' -show_streams -show_error'

  options = "#{base_options} -show_chapters" if ffprobe_version.version >= CHAPTER_SUPPORT

  options || base_options
end

#ffprobe_versionObject



46
47
48
# File 'lib/ffprober/ffmpeg/exec.rb', line 46

def ffprobe_version
  Ffprober::Ffmpeg::Version.new(self)
end

#ffprobe_version_outputObject



25
26
27
28
29
30
31
32
33
# File 'lib/ffprober/ffmpeg/exec.rb', line 25

def ffprobe_version_output
  @ffprobe_version_output ||= begin
    if @finder.path.nil?
      ''
    else
      `#{@finder.path} -version`
    end
  end
end

#json_output(filename) ⇒ Object



20
21
22
# File 'lib/ffprober/ffmpeg/exec.rb', line 20

def json_output(filename)
  `#{@finder.path} #{ffprobe_options} #{Shellwords.escape(filename)}`
end