Class: Abrizer::ProgressiveVp9

Inherits:
Object
  • Object
show all
Includes:
DebugSettings, FilepathHelpers
Defined in:
lib/abrizer/progressive_vp9.rb

Instance Method Summary collapse

Methods included from DebugSettings

#debug_settings

Methods included from FilepathHelpers

#adaptations_filepath, #audio_filepath, #audio_filepath_fragmented, #basename, #canvas_filepath, #canvas_partial_filepath, #captions_filepath, #data_filepath, #data_partial_filepath, #ffprobe_filepath, #filename_directory, #first_image_filepath, #hlsts_aac_filepath, #hlsts_aac_partial_filepath, #hlsts_filepath, #hlsts_partial_filepath, #mp3_filepath, #mp3_partial_filepath, #mp4_filepath, #mp4_partial_filepath, #mpd_filepath, #mpd_partial_filepath, #output_directory, #output_directory_basename, #poster_filepath, #poster_image_filepath, #poster_partial_filepath, #sprites_filepath, #sprites_partial_filepath, #vp9_filepath, #vp9_partial_filepath, #webvtt_input_filepath

Constructor Details

#initialize(filename, output_dir = nil) ⇒ ProgressiveVp9

Returns a new instance of ProgressiveVp9.



7
8
9
10
11
12
13
# File 'lib/abrizer/progressive_vp9.rb', line 7

def initialize(filename, output_dir=nil)
  @filename = filename
  @output_directory = output_dir
  make_directory
  Dir.chdir @output_directory
  find_adaptation
end

Instance Method Details

#bitrateObject

Since we are using the VP9 as a fallback we use half the bitrate we would use for an MP4 encode.



34
35
36
# File 'lib/abrizer/progressive_vp9.rb', line 34

def bitrate
  @adaptation.bitrate/2
end

#createObject



15
16
17
18
# File 'lib/abrizer/progressive_vp9.rb', line 15

def create
  `#{ffmpeg_cmd_pass1}`
  `#{ffmpeg_cmd_pass2}`
end

#ffmpeg_cmd_pass1Object



38
39
40
41
42
43
# File 'lib/abrizer/progressive_vp9.rb', line 38

def ffmpeg_cmd_pass1
  "ffmpeg -y #{debug_settings} -i #{@filename} -c:v libvpx-vp9 -crf 10 -b:v #{bitrate*1.1}k -c:a libvorbis \
   -vf yadif,scale='#{@adaptation.width}:trunc(#{@adaptation.width}/dar/2)*2',setsar=1 \
   -speed 4 -tile-columns 6 -frame-parallel 1 -pix_fmt yuv420p \
   -pass 1 -passlogfile ffmpeg2pass-webm -f webm /dev/null"
end

#ffmpeg_cmd_pass2Object



45
46
47
48
49
50
# File 'lib/abrizer/progressive_vp9.rb', line 45

def ffmpeg_cmd_pass2
  "ffmpeg -y #{debug_settings} -i #{@filename} -c:v libvpx-vp9 -crf 10 -b:v #{bitrate*1.1}k -c:a libvorbis \
   -vf yadif,scale='#{@adaptation.width}:trunc(#{@adaptation.width}/dar/2)*2',setsar=1 \
   -speed 1 -tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \
   -pass 2 -passlogfile ffmpeg2pass-webm -pix_fmt yuv420p #{static_filepath}"
end

#find_adaptationObject



24
25
26
27
28
29
30
# File 'lib/abrizer/progressive_vp9.rb', line 24

def find_adaptation
  adaptations = Abrizer::AdaptationFinder.new(@filename).adaptations
  sorted = adaptations.sort_by do |adaptation|
    adaptation.width
  end
  @adaptation = sorted.last
end

#make_directoryObject



20
21
22
# File 'lib/abrizer/progressive_vp9.rb', line 20

def make_directory
  FileUtils.mkdir_p @output_directory unless File.exist? @output_directory
end

#static_filepathObject



52
53
54
# File 'lib/abrizer/progressive_vp9.rb', line 52

def static_filepath
  File.join output_directory, "progressive-vp9.webm"
end