lib/vtools/video.rb in vtools-0.0.1 vs lib/vtools/video.rb in vtools-0.0.2
- old
+ new
@@ -9,11 +9,10 @@
:video_stream, :video_codec, :video_bitrate, :colorspace, :frame_rate,
:resolution, :dar, :audio_stream, :audio_codec, :audio_bitrate,
:audio_sample_rate,
:convert_options, :thumbs_options
- # json generator
def to_json(*args)
ignore = [:@convert_options, :@thumbs_options, :@converter, :@thumbnailer, :@uncertain_duration, :invalid]
hsh = instance_variables.inject({}) do |data, var|
data[ var[1..-1] ] = instance_variable_get(var) unless ignore.include? var.to_sym
@@ -22,11 +21,10 @@
hsh["valid"] = !@invalid
hsh.to_json(*args)
end
- # constructor
def initialize path
@invalid = true
@uncertain_duration = true
@convert_options = {}
@@ -95,32 +93,29 @@
@invalid = false unless @video_stream.to_s.empty?
@invalid = true if output.include?("is not supported")
self
end
-
- # define if is valid video file
+
def valid?
not @invalid
end
# validate duration
def uncertain_duration?
@uncertain_duration
end
- # width getter
def width
resolution.split("x").first.to_i rescue nil
end
- # height getter
def height
resolution.split("x").last.to_i rescue nil
end
- # aspect ratio getter
+ # aspect ratio calculator
def calculated_aspect_ratio
if dar
w, h = dar.split(":")
w.to_f / h.to_f
else
@@ -132,19 +127,18 @@
# video file size
def size
File.size(@path)
end
- # audio channels getter
+ # valid audio channels index
def audio_channels
return nil unless @audio_channels
return @audio_channels[/\d*/].to_i if @audio_channels["channels"]
return 1 if @audio_channels["mono"]
return 2 if @audio_channels["stereo"]
return 6 if @audio_channels["5.1"]
end
- # frame rate getter
def frame_rate
video_stream[/(\d*\.?\d*)\s?fps/] ? $1.to_f : nil
end
private