class VideoConverter::Input
Attributes
metadata_command[RW]
show_frames_command[RW]
show_streams_command[RW]
input[RW]
metadata[RW]
output_groups[RW]
Public Class Methods
new(input, outputs = [])
click to toggle source
# File lib/video_converter/input.rb, line 15 def initialize input, outputs = [] self.input = input or raise ArgumentError.new('Input requred') raise ArgumentError.new("#{input} does not exist") unless exists? end
Public Instance Methods
audio_stream()
click to toggle source
# File lib/video_converter/input.rb, line 69 def audio_stream metadata[:audio_streams].first end
crop_detect(samples = 5)
click to toggle source
# File lib/video_converter/input.rb, line 77 def crop_detect(samples = 5) (@crop_detect ||= samples.times.map do |sample| (metadata[:duration_in_ms] / (samples + 1) / 1000.0 * (sample + 1)).round end.uniq.map do |ss| Command.new(Ffmpeg.crop_detect_command, :bin => Ffmpeg.bin, :ss => ss, :input => input, :vframes => 2).capture .match(/Parsed_cropdetect.+crop=(?<crop>(?<w>[-\d]+):(?<h>[-\d]+):(?<x>\d+):(?<y>\d+))/) end.compact.max do |m1, m2| res = m1[:h].to_i <=> m2[:h].to_i res = m1[:w].to_i <=> m2[:w].to_i if res == 0 res end || {})[:crop] end
key_frames()
click to toggle source
# File lib/video_converter/input.rb, line 90 def key_frames @key_frames ||= Command.new(Ffmpeg.key_frames_command, :bin => Ffmpeg.bin, :input => input).capture.split("\n").map do |l| if m = l.match(/pts:\s*(\d+)\s*pts_time:\s*(\d+(?:\.\d+)?)/) { :pts => m[1].to_i, :pts_time => m[2].to_f } end end.compact end
mean_volume()
click to toggle source
# File lib/video_converter/input.rb, line 73 def mean_volume @mean_volume ||= Command.new(Ffmpeg.volume_detect_command, :bin => Ffmpeg.bin, :input => input).capture.match(/mean_volume:\s([-\d.]+)\sdB/).to_a[1] end
select_outputs(outputs)
click to toggle source
# File lib/video_converter/input.rb, line 98 def select_outputs(outputs) outputs.select { |output| !output.path || output.path == input } end
to_s()
click to toggle source
# File lib/video_converter/input.rb, line 20 def to_s input end
video_stream()
click to toggle source
# File lib/video_converter/input.rb, line 65 def video_stream metadata[:video_streams].first end
Private Instance Methods
exists?()
click to toggle source
# File lib/video_converter/input.rb, line 118 def exists? if is_http? url = URI.parse(input) Net::HTTP.start(url.host) do |http| response = http.request_head url.path Net::HTTPSuccess === response end else is_local? end end
is_http?()
click to toggle source
# File lib/video_converter/input.rb, line 130 def is_http? !!input.match(/^http:\/\//) end
is_local?()
click to toggle source
# File lib/video_converter/input.rb, line 134 def is_local? File.file?(input) end