Class: Abrizer::Adaptation
- Inherits:
-
Object
- Object
- Abrizer::Adaptation
- Includes:
- FilepathHelpers
- Defined in:
- lib/abrizer/adaptation.rb
Instance Attribute Summary collapse
-
#bitrate ⇒ Object
readonly
Returns the value of attribute bitrate.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#constrained_bitrate ⇒ Object
TODO: make the constrained bitrate (maxrate) value configurable.
- #ffmpeg_cmd(input, output_directory, pass) ⇒ Object
- #filepath(input, output_directory) ⇒ Object
- #filepath_fragmented(input, output_directory) ⇒ Object
-
#initialize(width:, height:, bitrate:) ⇒ Adaptation
constructor
A new instance of Adaptation.
- #outfile_basename(input) ⇒ Object
- #to_s ⇒ Object
Methods included from FilepathHelpers
#audio_filepath, #audio_filepath_fragmented, #basename, #canvas_filepath, #canvas_partial_filepath, #filename_directory, #first_image_filepath, #hlsts_aac_filepath, #hlsts_aac_partial_filepath, #hlsts_filepath, #hlsts_partial_filepath, #mp4_filepath, #mp4_partial_filepath, #mpd_filepath, #mpd_partial_filepath, #output_directory, #output_directory_basename, #poster_image_filepath, #poster_partial_filepath, #sprites_filepath, #sprites_partial_filepath, #vp9_filepath, #vp9_partial_filepath, #webvtt_input_filepath
Constructor Details
#initialize(width:, height:, bitrate:) ⇒ Adaptation
Returns a new instance of Adaptation.
8 9 10 11 12 |
# File 'lib/abrizer/adaptation.rb', line 8 def initialize(width:, height:, bitrate:) @width = width @height = height @bitrate = bitrate end |
Instance Attribute Details
#bitrate ⇒ Object (readonly)
Returns the value of attribute bitrate.
6 7 8 |
# File 'lib/abrizer/adaptation.rb', line 6 def bitrate @bitrate end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/abrizer/adaptation.rb', line 6 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/abrizer/adaptation.rb', line 6 def width @width end |
Instance Method Details
#constrained_bitrate ⇒ Object
TODO: make the constrained bitrate (maxrate) value configurable
28 29 30 |
# File 'lib/abrizer/adaptation.rb', line 28 def constrained_bitrate @bitrate * 1.1 end |
#ffmpeg_cmd(input, output_directory, pass) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/abrizer/adaptation.rb', line 14 def ffmpeg_cmd(input, output_directory, pass) cmd = %Q|ffmpeg -y -i #{input} -vf \ scale='#{width}:trunc(#{width}/dar/2)*2',setsar=1 \ -an -c:v libx264 -x264opts 'keyint=48:min-keyint=48:no-scenecut' \ -b:v #{bitrate}k -preset faster | if pass == 2 cmd += %Q| -maxrate #{constrained_bitrate}k -bufsize #{bitrate}k -pass 2 #{filepath(input, output_directory)} | else cmd += " -pass 1 -f mp4 /dev/null " end cmd end |
#filepath(input, output_directory) ⇒ Object
38 39 40 41 |
# File 'lib/abrizer/adaptation.rb', line 38 def filepath(input, output_directory) name = "#{outfile_basename(input)}.mp4" File.join output_directory, name end |
#filepath_fragmented(input, output_directory) ⇒ Object
43 44 45 46 |
# File 'lib/abrizer/adaptation.rb', line 43 def filepath_fragmented(input, output_directory) name = "#{outfile_basename(input)}-frag.mp4" File.join output_directory, name end |
#outfile_basename(input) ⇒ Object
32 33 34 35 36 |
# File 'lib/abrizer/adaptation.rb', line 32 def outfile_basename(input) extname = File.extname input basename = File.basename input, extname "#{basename}-#{width}x#{height}-#{bitrate}" end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/abrizer/adaptation.rb', line 48 def to_s "Width: #{@width}, Height: #{@height}, Bitrate: #{@bitrate}" end |