Class: RVideo::Tools::Ffmpeg

Inherits:
Object
  • Object
show all
Includes:
AbstractTool::InstanceMethods
Defined in:
lib/rvideo/tools/ffmpeg.rb

Instance Attribute Summary collapse

Attributes included from AbstractTool::InstanceMethods

#command, #options, #original, #raw_result

Instance Method Summary collapse

Methods included from AbstractTool::InstanceMethods

#audio_bit_rate, #audio_channels, #audio_sample_rate, #calculate_height, #calculate_width, #execute, #fps, #get_audio_bit_rate, #get_audio_channels, #get_audio_sample_rate, #get_fit_to_height_resolution, #get_fit_to_width_resolution, #get_fps, #get_letterbox_resolution, #get_mono_audio, #get_original_fps, #get_original_resolution, #get_resolution, #get_specific_audio_bit_rate, #get_specific_audio_sample_rate, #get_specific_fps, #get_specific_resolution, #get_stereo_audio, #get_video_quality, #initialize, #resolution, #temp_dir, #valid_dimension?, #video_quality

Instance Attribute Details

#audio_sizeObject (readonly)

Returns the value of attribute audio_size.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def audio_size
  @audio_size
end

#frameObject (readonly)

Returns the value of attribute frame.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def frame
  @frame
end

#header_sizeObject (readonly)

Returns the value of attribute header_size.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def header_size
  @header_size
end

#output_bitrateObject (readonly)

Returns the value of attribute output_bitrate.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def output_bitrate
  @output_bitrate
end

#output_fpsObject (readonly)

Returns the value of attribute output_fps.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def output_fps
  @output_fps
end

#overheadObject (readonly)

Returns the value of attribute overhead.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def overhead
  @overhead
end

#psnrObject (readonly)

Returns the value of attribute psnr.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def psnr
  @psnr
end

#qObject (readonly)

Returns the value of attribute q.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def q
  @q
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def time
  @time
end

#video_sizeObject (readonly)

Returns the value of attribute video_size.



6
7
8
# File 'lib/rvideo/tools/ffmpeg.rb', line 6

def video_size
  @video_size
end

Instance Method Details

#format_audio_bit_rate(params = {}) ⇒ Object



49
50
51
# File 'lib/rvideo/tools/ffmpeg.rb', line 49

def format_audio_bit_rate(params={})
  " -ab #{params[:bit_rate]}k"
end

#format_audio_channels(params = {}) ⇒ Object



45
46
47
# File 'lib/rvideo/tools/ffmpeg.rb', line 45

def format_audio_channels(params={})
  " -ac #{params[:channels]}"
end

#format_audio_sample_rate(params = {}) ⇒ Object



53
54
55
# File 'lib/rvideo/tools/ffmpeg.rb', line 53

def format_audio_sample_rate(params={})
  " -ar #{params[:sample_rate]}"
end

#format_fps(params = {}) ⇒ Object



13
14
15
# File 'lib/rvideo/tools/ffmpeg.rb', line 13

def format_fps(params={})
  " -r #{params[:fps]}"
end

#format_resolution(params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/rvideo/tools/ffmpeg.rb', line 35

def format_resolution(params={})
  p = " -s #{params[:scale][:width]}x#{params[:scale][:height]} "
  if params[:letterbox]
    plr = ((params[:letterbox][:width] - params[:scale][:width]) / 2).to_i
    ptb = ((params[:letterbox][:height] - params[:scale][:height]) / 2).to_i
    p += " -padtop #{ptb} -padbottom #{ptb} -padleft #{plr} -padright #{plr} "
  end
  p
end

#format_video_quality(params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rvideo/tools/ffmpeg.rb', line 16

def format_video_quality(params={})
  bitrate = params[:video_bit_rate].blank? ? nil : params[:video_bit_rate]
  factor = (params[:scale][:width].to_f * params[:scale][:height].to_f * params[:fps].to_f)
  case params[:video_quality]
  when 'low'
    bitrate ||= (factor / 12000).to_i
    " -v #{bitrate}k -crf 30 -me zero -subq 1 -refs 1 -threads auto "
  when 'medium'
    bitrate ||= (factor / 9000).to_i
    " -v #{bitrate}k -crf 22 -flags +loop -cmp +sad -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me hex -subq 3 -trellis 1 -refs 2 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250"
  when 'high'
    bitrate ||= (factor / 3600).to_i
    " -v #{bitrate}k -crf 18 -flags +loop -cmp +sad -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me full -subq 6 -trellis 1 -refs 3 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71"
  else
    ""
  end
end

#tool_commandObject

Not sure if this is needed anymore…



9
10
11
# File 'lib/rvideo/tools/ffmpeg.rb', line 9

def tool_command
  'ffmpeg'
end