class FFMPEG::EncodingOptions

Public Class Methods

new(options = {}) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 3
def initialize(options = {})
  merge!(options)
end

Public Instance Methods

height() click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 29
def height
  self[:resolution].split("x").last.to_i rescue nil
end
to_s() click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 7
def to_s
  params = collect do |key, value|
    send("convert_#{key}", value) if value && supports_option?(key)
  end

  # codecs should go before the presets so that the files will be matched successfully
  # all other parameters go after so that we can override whatever is in the preset
  codecs = params.select { |p| p =~ /codec/ }
  presets = params.select { |p| p =~ /\-.pre/ }
  watermarkoptions = params.select { |p| p =~ /i / || p=~ /filter_complex/ }  
  other = params - codecs - presets - watermarkoptions
  params = watermarkoptions + codecs + presets + other

  params_string = params.join(" ")
  params_string << " #{convert_aspect(calculate_aspect)}" if calculate_aspect?
  params_string
end
width() click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 25
def width
  self[:resolution].split("x").first.to_i rescue nil
end

Private Instance Methods

calculate_aspect() click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 44
def calculate_aspect
  width, height = self[:resolution].split("x")
  width.to_f / height.to_f
end
calculate_aspect?() click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 49
def calculate_aspect?
  self[:aspect].nil? && self[:resolution]
end
convert_aspect(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 40
def convert_aspect(value)
  "-aspect #{value}"
end
convert_audio_bitrate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 73
def convert_audio_bitrate(value)
  "-b:a #{k_format(value)}"
end
convert_audio_channels(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 81
def convert_audio_channels(value)
  "-ac #{value}"
end
convert_audio_codec(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 69
def convert_audio_codec(value)
  "-acodec #{value}"
end
convert_audio_preset(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 117
def convert_audio_preset(value)
  "-apre #{value}"
end
convert_audio_sample_rate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 77
def convert_audio_sample_rate(value)
  "-ar #{value}"
end
convert_buffer_size(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 93
def convert_buffer_size(value)
  "-bufsize #{k_format(value)}"
end
convert_custom(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 171
def convert_custom(value)
  value
end
convert_duration(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 109
def convert_duration(value)
  "-t #{value}"
end
convert_file_preset(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 121
def convert_file_preset(value)
  "-fpre #{value}"
end
convert_frame_rate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 57
def convert_frame_rate(value)
  "-r #{value}"
end
convert_keyframe_interval(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 125
def convert_keyframe_interval(value)
  "-g #{value}"
end
convert_quality(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 138
def convert_quality(value)
  "-q:v #{value}"
end
convert_resolution(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 61
def convert_resolution(value)
  "-s #{value}"
end
convert_screenshot(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 133
def convert_screenshot(value)
  vframes = '-vframes 1 ' unless self[:vframes]
  value ? "#{vframes}-f image2" : ""
end
convert_seek_time(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 129
def convert_seek_time(value)
  "-ss #{value}"
end
convert_target(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 105
def convert_target(value)
  "-target #{value}"
end
convert_threads(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 101
def convert_threads(value)
  "-threads #{value}"
end
convert_vframes(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 142
def convert_vframes(value)
  "-vframes #{value}"
end
convert_video_bitrate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 65
def convert_video_bitrate(value)
  "-b:v #{k_format(value)}"
end
convert_video_bitrate_tolerance(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 97
def convert_video_bitrate_tolerance(value)
  "-bt #{k_format(value)}"
end
convert_video_codec(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 53
def convert_video_codec(value)
  "-vcodec #{value}"
end
convert_video_max_bitrate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 85
def convert_video_max_bitrate(value)
  "-maxrate #{k_format(value)}"
end
convert_video_min_bitrate(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 89
def convert_video_min_bitrate(value)
  "-minrate #{k_format(value)}"
end
convert_video_preset(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 113
def convert_video_preset(value)
  "-vpre #{value}"
end
convert_watermark(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 154
def convert_watermark(value)
  "-i #{value}"
end
convert_watermark_filter(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 158
def convert_watermark_filter(value)
  case value[:position].to_s
  when "LT"
    "-filter_complex 'scale=#{self[:resolution]},overlay=x=#{value[:padding_x]}:y=#{value[:padding_y]}'"
  when "RT"
    "-filter_complex 'scale=#{self[:resolution]},overlay=x=main_w-overlay_w-#{value[:padding_x]}:y=#{value[:padding_y]}'"
  when "LB"
    "-filter_complex 'scale=#{self[:resolution]},overlay=x=#{value[:padding_x]}:y=main_h-overlay_h-#{value[:padding_y]}'"
  when "RB"
    "-filter_complex 'scale=#{self[:resolution]},overlay=x=main_w-overlay_w-#{value[:padding_x]}:y=main_h-overlay_h-#{value[:padding_y]}'"
  end  
end
convert_x264_preset(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 150
def convert_x264_preset(value)
  "-preset #{value}"
end
convert_x264_vprofile(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 146
def convert_x264_vprofile(value)
  "-vprofile #{value}"
end
k_format(value) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 175
def k_format(value)
  value.to_s.include?("k") ? value : "#{value}k"
end
supports_option?(option) click to toggle source
# File lib/ffmpeg/encoding_options.rb, line 35
def supports_option?(option)
  option = RUBY_VERSION < "1.9" ? "convert_#{option}" : "convert_#{option}".to_sym
  private_methods.include?(option)
end