Class: Abrizer::FfmpegProcessor
Overview
Creates the fMP4 files that are then packaged
Instance Method Summary
collapse
#debug_settings
#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) ⇒ FfmpegProcessor
Returns a new instance of FfmpegProcessor.
8
9
10
11
12
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 8
def initialize(filename, output_dir)
@filename = filename
@output_directory = output_dir
@adaptation_finder = Abrizer::AdaptationFinder.new(filepath: @filename)
end
|
Instance Method Details
#first_pass_adaptation ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 26
def first_pass_adaptation
adaptations = Abrizer::AdaptationFinder.new(filepath: @filename).adaptations
sorted = adaptations.sort_by do |adaptation|
adaptation.width
end
sorted[-2]
end
|
#first_pass_cmd ⇒ Object
34
35
36
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 34
def first_pass_cmd
first_pass_adaptation.ffmpeg_cmd(@filename, output_directory, 1)
end
|
#make_directory ⇒ Object
22
23
24
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 22
def make_directory
FileUtils.mkdir_p output_directory unless File.exist? output_directory
end
|
#process ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 14
def process
make_directory
Dir.chdir output_directory
process_first_pass
process_second_passes
process_audio
end
|
#process_audio ⇒ Object
54
55
56
57
58
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 54
def process_audio
`ffmpeg -y #{debug_settings} -i #{@filename} -c:a libfdk_aac -b:a 128k -vn #{audio_filepath}`
`mp4fragment #{audio_filepath} #{audio_filepath_fragmented}`
FileUtils.rm audio_filepath
end
|
#process_first_pass ⇒ Object
38
39
40
41
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 38
def process_first_pass
puts first_pass_cmd
`#{first_pass_cmd}`
end
|
#process_second_passes ⇒ Object
Creates a file per adaptation based on aspect ratio and resolution
44
45
46
47
48
49
50
51
52
|
# File 'lib/abrizer/ffmpeg_processor.rb', line 44
def process_second_passes
@adaptation_finder.adaptations.each do |adaptation|
cmd = adaptation.ffmpeg_cmd(@filename, output_directory, 2)
puts cmd
`#{cmd}`
`mp4fragment #{adaptation.filepath(output_directory)} #{adaptation.filepath_fragmented(output_directory)}`
FileUtils.rm adaptation.filepath(output_directory)
end
end
|