class FfmpegWrapper::FFprobe
Public Class Methods
new(filename)
click to toggle source
@param [String] filename
# File lib/ffmpeg_wrapper/ffprobe.rb, line 42 def initialize(filename) @input = filename || fail(ArgumentError 'No input specified') @command = 'ffprobe ' @show_specifiers = [] @options = {} end
run(filename, &block)
click to toggle source
Execute ffprobe command. @param [String] filename @return [Hash] @example
info = FFprobe.run('video.mp4') do show_streams show_format end info #=> { "format" => ..., "streams"=>... } info['format']['codec_type'] #=> 'video'
# File lib/ffmpeg_wrapper/ffprobe.rb, line 16 def run(filename, &block) ff = FFprobe.new filename ff.instance_eval do @command << ' -v quiet -of json' instance_eval &block if block @command << @show_specifiers.reduce(' ') do |acc, v| acc << " -#{v}" acc end @command << ' ' << @options.to_shellflags @command << ' ' << @input out = `#{@command} 2>/dev/null` begin @result = JSON.parse out fail if @result.keys.empty? rescue @result = { 'errors' => error } # FIXME: Do not return from ensure ensure return @result end end end
Public Instance Methods
options(hash)
click to toggle source
Specify input file options @param [Hash] options
# File lib/ffmpeg_wrapper/ffprobe.rb, line 51 def options(hash) @options.merge! hash end
Also aliased as: option
Private Instance Methods
error()
click to toggle source
# File lib/ffmpeg_wrapper/ffprobe.rb, line 67 def error @command.gsub!('-v quiet', '-v error') @command.gsub!('-of json', '') `#{@command} 2>&1` end
method_missing(meth, *args, &blk)
click to toggle source
Calls superclass method
# File lib/ffmpeg_wrapper/ffprobe.rb, line 58 def method_missing(meth, *args, &blk) case meth when /show_(\w+)/ then @show_specifiers << meth else super end end