Class: Abrizer::PackageHlsShaka

Inherits:
Object
  • Object
show all
Includes:
FilepathHelpers
Defined in:
lib/abrizer/package_hls_shaka.rb

Instance Method Summary collapse

Methods included from FilepathHelpers

#adaptations_filepath, #all_media_paths, #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) ⇒ PackageHlsShaka

Returns a new instance of PackageHlsShaka.



6
7
8
9
# File 'lib/abrizer/package_hls_shaka.rb', line 6

def initialize(filename, output_dir=nil)
  @filename = filename
  @adaptations = Abrizer::AdaptationFinder.new(filepath: @filename).adaptations
end

Instance Method Details

#audio_inputObject



27
28
29
30
31
# File 'lib/abrizer/package_hls_shaka.rb', line 27

def audio_input
  hls_audio_filename = "#{basename}-audio-$Number$.ts"
  hls_audio_playlist = "#{basename}-audio.m3u8"
  %Q| 'input=#{audio_filepath},stream=audio,segment_template=#{hls_audio_filename},playlist_name=#{hls_audio_playlist},hls_group_id=AUDIO,hls_name=ENGLISH' |
end

#hls_directoryObject



45
46
47
# File 'lib/abrizer/package_hls_shaka.rb', line 45

def hls_directory
  File.join output_directory, 'hls'
end

#make_directoryObject



41
42
43
# File 'lib/abrizer/package_hls_shaka.rb', line 41

def make_directory
  FileUtils.mkdir_p hls_directory unless File.exist? hls_directory
end

#mpd_filenameObject



33
34
35
# File 'lib/abrizer/package_hls_shaka.rb', line 33

def mpd_filename
  File.join 'dash', "#{basename}.mpd"
end

#packageObject



11
12
13
14
15
# File 'lib/abrizer/package_hls_shaka.rb', line 11

def package
  make_directory
  Dir.chdir hls_directory
  `#{shaka_cmd}`
end

#shaka_cmdObject



37
38
39
# File 'lib/abrizer/package_hls_shaka.rb', line 37

def shaka_cmd
  %Q|shaka-packager #{video_inputs.join(' ')} #{audio_input} --single_segment=false --hls_master_playlist_output=#{basename}.m3u8|
end

#video_inputsObject



17
18
19
20
21
22
23
24
25
# File 'lib/abrizer/package_hls_shaka.rb', line 17

def video_inputs
  @adaptations.map do |adaptation|
    filepath = adaptation.filepath(@filename)
    adaptation_basename = File.basename filepath, '.mp4'
    segment_template = "#{adaptation_basename}-$Number$.ts"
    adaptation_hls_playlist = "#{adaptation_basename}.m3u8"
    %Q|'input=#{filepath},stream=video,segment_template=#{segment_template},playlist_name=#{adaptation_hls_playlist}'|
  end
end