Class: RVideo::Tools::Ffmpeg
- Inherits:
-
Object
- Object
- RVideo::Tools::Ffmpeg
- Includes:
- AbstractTool::InstanceMethods
- Defined in:
- lib/rvideo/tools/ffmpeg.rb
Constant Summary collapse
- RESOLUTION_ABBREVIATIONS =
{ "sqcif" => "128x96", "qcif" => "176x144", "cif" => "352x288", "4cif" => "704x576", "qqvga" => "160x120", "qvga" => "320x240", "vga" => "640x480", "svga" => "800x600", "xga" => "1024x768", "uxga" => "1600x1200", "qxga" => "2048x1536", "sxga" => "1280x1024", "qsxga" => "2560x2048", "hsxga" => "5120x4096", "wvga" => "852x480", "wxga" => "1366x768", "wsxga" => "1600x1024", "wuxga" => "1920x1200", "woxga" => "2560x1600", "wqsxga" => "3200x2048", "wquxga" => "3840x2400", "whsxga" => "6400x4096", "whuxga" => "7680x4800", "cga" => "320x200", "ega" => "640x350", "hd480" => "852x480", "hd720" => "1280x720", "hd1080" => "1920x1080" }
- VALID_ASPECT_STRINGS =
["4:3", "16:9"]
- VALID_ASPECT_FLOATS =
[1.3333, 1.7777]
- DEFAULT_VIDEO_BIT_RATE_PARAMETER =
The flag used to set video bitrate has apparently changed between different ffmpeg versions. In the latest builds -b is used. In older builds it was -v which is now used to set verbosity of logging.
"b"
Instance Attribute Summary collapse
-
#audio_size ⇒ Object
readonly
Returns the value of attribute audio_size.
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#header_size ⇒ Object
readonly
Returns the value of attribute header_size.
-
#output_bitrate ⇒ Object
readonly
Returns the value of attribute output_bitrate.
-
#output_fps ⇒ Object
readonly
Returns the value of attribute output_fps.
-
#overhead ⇒ Object
readonly
Returns the value of attribute overhead.
-
#psnr ⇒ Object
readonly
Returns the value of attribute psnr.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#video_size ⇒ Object
readonly
Returns the value of attribute video_size.
Attributes included from AbstractTool::InstanceMethods
#command, #options, #original, #raw_result
Instance Method Summary collapse
- #format_audio_bit_rate(params = {}) ⇒ Object
- #format_audio_channels(params = {}) ⇒ Object
- #format_audio_sample_rate(params = {}) ⇒ Object
- #format_deinterlace(params = {}) ⇒ Object
- #format_fps(params = {}) ⇒ Object
- #format_resolution(params = {}) ⇒ Object
- #format_video_bit_rate(params = {}) ⇒ Object
- #format_video_bit_rate_max(params = {}) ⇒ Object
- #format_video_bit_rate_min(params = {}) ⇒ Object
- #format_video_bit_rate_tolerance(params = {}) ⇒ Object
- #format_video_quality(params = {}) ⇒ Object
-
#tool_command ⇒ Object
Not sure if this is needed anymore…
Methods included from AbstractTool::InstanceMethods
abstract_attribute_formatter, #audio_bit_rate, #audio_channels, #audio_sample_rate, #calculate_height, #calculate_width, #deinterlace, #do_execute, #execute, #fps, #get_audio_bit_rate, #get_audio_channels, #get_audio_sample_rate, #get_deinterlace, #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_bit_rate, #get_video_bit_rate_max, #get_video_bit_rate_min, #get_video_bit_rate_tolerance, #get_video_quality, #initialize, #resolution, #temp_dir, #valid_dimension?, #video_bit_rate, #video_bit_rate_max, #video_bit_rate_min, #video_bit_rate_tolerance, #video_quality
Instance Attribute Details
#audio_size ⇒ Object (readonly)
Returns the value of attribute audio_size.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def audio_size @audio_size end |
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def frame @frame end |
#header_size ⇒ Object (readonly)
Returns the value of attribute header_size.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def header_size @header_size end |
#output_bitrate ⇒ Object (readonly)
Returns the value of attribute output_bitrate.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def output_bitrate @output_bitrate end |
#output_fps ⇒ Object (readonly)
Returns the value of attribute output_fps.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def output_fps @output_fps end |
#overhead ⇒ Object (readonly)
Returns the value of attribute overhead.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def overhead @overhead end |
#psnr ⇒ Object (readonly)
Returns the value of attribute psnr.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def psnr @psnr end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def q @q end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def size @size end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def time @time end |
#video_size ⇒ Object (readonly)
Returns the value of attribute video_size.
47 48 49 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 47 def video_size @video_size end |
Instance Method Details
#format_audio_bit_rate(params = {}) ⇒ Object
115 116 117 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 115 def format_audio_bit_rate(params={}) "-ab #{params[:bit_rate]}k" end |
#format_audio_channels(params = {}) ⇒ Object
111 112 113 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 111 def format_audio_channels(params={}) "-ac #{params[:channels]}" end |
#format_audio_sample_rate(params = {}) ⇒ Object
119 120 121 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 119 def format_audio_sample_rate(params={}) "-ar #{params[:sample_rate]}" end |
#format_deinterlace(params = {}) ⇒ Object
54 55 56 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 54 def format_deinterlace(params={}) params[:deinterlace] ? "-deinterlace" : "" end |
#format_fps(params = {}) ⇒ Object
58 59 60 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 58 def format_fps(params={}) "-r #{params[:fps]}" end |
#format_resolution(params = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 101 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_bit_rate(params = {}) ⇒ Object
62 63 64 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 62 def format_video_bit_rate(params = {}) "-#{video_bit_rate_parameter} #{params[:video_bit_rate]}k" end |
#format_video_bit_rate_max(params = {}) ⇒ Object
74 75 76 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 74 def format_video_bit_rate_max(params = {}) "-maxrate #{params[:video_bit_rate_max]}k" end |
#format_video_bit_rate_min(params = {}) ⇒ Object
70 71 72 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 70 def format_video_bit_rate_min(params = {}) "-minrate #{params[:video_bit_rate_min]}k" end |
#format_video_bit_rate_tolerance(params = {}) ⇒ Object
66 67 68 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 66 def format_video_bit_rate_tolerance(params = {}) "-bt #{params[:video_bit_rate_tolerance]}k" end |
#format_video_quality(params = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 78 def format_video_quality(params={}) bitrate = params[:video_bit_rate].blank? ? nil : params[:video_bit_rate] params.merge! get_original_fps unless params[:fps] 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 params[:video_bit_rate] = bitrate "#{format_video_bit_rate params} -crf 30 -me zero -subq 1 -refs 1 -threads auto" when 'medium' bitrate ||= (factor / 9000).to_i params[:video_bit_rate] = bitrate "#{format_video_bit_rate params} -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 params[:video_bit_rate] = bitrate "#{format_video_bit_rate params} -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" end end |
#tool_command ⇒ Object
Not sure if this is needed anymore…
50 51 52 |
# File 'lib/rvideo/tools/ffmpeg.rb', line 50 def tool_command 'ffmpeg' end |