Skip to content

Instantly share code, notes, and snippets.

@greatseth
Created February 19, 2009 19:31
Show Gist options
  • Save greatseth/67074 to your computer and use it in GitHub Desktop.
Save greatseth/67074 to your computer and use it in GitHub Desktop.
# 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.
cattr_accessor :video_bit_rate_parameter
self.video_bit_rate_parameter = "b"
include AbstractTool::InstanceMethods
attr_reader :frame, :q, :size, :time, :output_bitrate, :video_size, :audio_size, :header_size, :overhead, :psnr, :output_fps
# Not sure if this is needed anymore...
def tool_command
'ffmpeg'
end
def format_fps(params={})
"-r #{params[:fps]}"
end
def format_video_bit_rate(params = {})
"-#{video_bit_rate_parameter} #{params[:video_bit_rate]}k"
end
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
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
" #{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
" #{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"
else
""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment