Class: VideoConverter::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/video_converter/input.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, outputs = []) ⇒ Input

Returns a new instance of Input.

Raises:

  • (ArgumentError)


15
16
17
18
# 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

Class Attribute Details

.metadata_commandObject

Returns the value of attribute metadata_command.



6
7
8
# File 'lib/video_converter/input.rb', line 6

def 
  @metadata_command
end

.show_frames_commandObject

Returns the value of attribute show_frames_command.



6
7
8
# File 'lib/video_converter/input.rb', line 6

def show_frames_command
  @show_frames_command
end

.show_streams_commandObject

Returns the value of attribute show_streams_command.



6
7
8
# File 'lib/video_converter/input.rb', line 6

def show_streams_command
  @show_streams_command
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



13
14
15
# File 'lib/video_converter/input.rb', line 13

def input
  @input
end

#metadataObject

Returns the value of attribute metadata.



13
14
15
# File 'lib/video_converter/input.rb', line 13

def 
  @metadata
end

#output_groups(outputs) ⇒ Object

Returns the value of attribute output_groups.



13
14
15
# File 'lib/video_converter/input.rb', line 13

def output_groups
  @output_groups
end

Instance Method Details

#audio_streamObject



69
70
71
# File 'lib/video_converter/input.rb', line 69

def audio_stream
  [:audio_streams].first
end

#crop_detect(samples = 5) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/video_converter/input.rb', line 77

def crop_detect(samples = 5)
  (@crop_detect ||= samples.times.map do |sample|
    ([: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_framesObject



90
91
92
93
94
95
96
# 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_volumeObject



73
74
75
# 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) ⇒ Object



98
99
100
# File 'lib/video_converter/input.rb', line 98

def select_outputs(outputs)
  outputs.select { |output| !output.path || output.path == input }
end

#to_sObject



20
21
22
# File 'lib/video_converter/input.rb', line 20

def to_s
  input
end

#video_streamObject



65
66
67
# File 'lib/video_converter/input.rb', line 65

def video_stream
  [:video_streams].first
end