Sha256: ffc313ec1a30f7dbc1eaa1d7cff455ed82e09255e57585e018a08a82296aee88

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

module Abrizer
  class PackageHlsShaka

    include FilepathHelpers

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

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

    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

    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

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

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

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

    def hls_directory
      File.join output_directory, 'hls'
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
abrizer-0.6.0 lib/abrizer/package_hls_shaka.rb
abrizer-0.5.0 lib/abrizer/package_hls_shaka.rb