Class: Abrizer::ProgressiveMp4

Inherits:
Object
  • Object
show all
Includes:
FilepathHelpers
Defined in:
lib/abrizer/progressive_mp4.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(output_dir) ⇒ ProgressiveMp4

Returns a new instance of ProgressiveMp4.



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

def initialize(output_dir)
  @output_directory = output_dir
  find_adaptation
end

Instance Method Details

#createObject



11
12
13
14
15
16
17
# File 'lib/abrizer/progressive_mp4.rb', line 11

def create
  if File.exist? input_video_filepath
    `#{ffmpeg_cmd}`
  else
    raise Mp4AdaptationNotFoundError
  end
end

#ffmpeg_cmdObject



31
32
33
34
35
# File 'lib/abrizer/progressive_mp4.rb', line 31

def ffmpeg_cmd
  "ffmpeg -y -i #{input_video_filepath} -i #{audio_filepath_fragmented} -c:v copy -c:a copy #{mp4_filepath} -movflags faststart"
  # Previously used command:
  # "ffmpeg -y -i #{@filename} -profile:v high -pix_fmt yuv420p -movflags faststart -b:v #{@adaptation.bitrate}k #{mp4_filepath}"
end

#find_adaptationObject



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

def find_adaptation
  adaptations = Abrizer::AdaptationFinder.new(output_directory: @output_directory).adaptations
  sorted = adaptations.sort_by do |adaptation|
   adaptation.width
  end
  @adaptation = sorted[-2]
end

#input_video_filepathObject



27
28
29
# File 'lib/abrizer/progressive_mp4.rb', line 27

def input_video_filepath
  @adaptation.filepath_fragmented(@output_directory)
end