Sha256: 84cf8ff7fa225468e322a7c892ef93e78ca48dae5febcb818004fa5c95e3c95e
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
module Abrizer class Adaptation include FilepathHelpers attr_reader :width, :height, :bitrate def initialize(width:, height:, bitrate:) @width = width @height = height @bitrate = bitrate end 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 # TODO: make the constrained bitrate (maxrate) value configurable def constrained_bitrate @bitrate * 1.1 end def outfile_basename(input) extname = File.extname input basename = File.basename input, extname "#{basename}-#{width}x#{height}-#{bitrate}" end def filepath(input, output_directory) name = "#{outfile_basename(input)}.mp4" File.join output_directory, name end def filepath_fragmented(input, output_directory) name = "#{outfile_basename(input)}-frag.mp4" File.join output_directory, name end def to_s "Width: #{@width}, Height: #{@height}, Bitrate: #{@bitrate}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
abrizer-0.3.0 | lib/abrizer/adaptation.rb |
abrizer-0.2.0 | lib/abrizer/adaptation.rb |
abrizer-0.1.0 | lib/abrizer/adaptation.rb |