Class: Abrizer::Adaptation
Instance Attribute Summary collapse
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(width:, height:, bitrate:) ⇒ Adaptation
Returns a new instance of Adaptation.
9
10
11
12
13
|
# File 'lib/abrizer/adaptation.rb', line 9
def initialize(width:, height:, bitrate:)
@width = width
@height = height
@bitrate = bitrate
end
|
Instance Attribute Details
#bitrate ⇒ Object
Returns the value of attribute bitrate.
7
8
9
|
# File 'lib/abrizer/adaptation.rb', line 7
def bitrate
@bitrate
end
|
#height ⇒ Object
Returns the value of attribute height.
7
8
9
|
# File 'lib/abrizer/adaptation.rb', line 7
def height
@height
end
|
#width ⇒ Object
Returns the value of attribute width.
7
8
9
|
# File 'lib/abrizer/adaptation.rb', line 7
def width
@width
end
|
Instance Method Details
#constrained_bitrate ⇒ Object
TODO: make the constrained bitrate (maxrate) value configurable
30
31
32
|
# File 'lib/abrizer/adaptation.rb', line 30
def constrained_bitrate
@bitrate * 1.1
end
|
#ffmpeg_cmd(input, output_directory, pass) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/abrizer/adaptation.rb', line 15
def ffmpeg_cmd(input, output_directory, pass)
cmd = %Q|ffmpeg -y #{debug_settings} \
-i #{input} -vf \
yadif,scale='#{width}:trunc(#{width}/dar/2)*2',setsar=1 \
-an -c:v libx264 -x264opts 'keyint=48:min-keyint=48:no-scenecut' \
-b:v #{bitrate}k -preset faster -pix_fmt yuv420p |
if pass == 2
cmd += %Q| -maxrate #{constrained_bitrate}k -bufsize #{bitrate}k -pass 2 #{filepath(output_directory)} |
else
cmd += " -pass 1 -f mp4 /dev/null "
end
cmd
end
|
#filepath(output_directory) ⇒ Object
38
39
40
41
|
# File 'lib/abrizer/adaptation.rb', line 38
def filepath(output_directory)
name = "#{outfile_basename}.mp4"
File.join output_directory, name
end
|
#filepath_fragmented(output_directory) ⇒ Object
43
44
45
46
|
# File 'lib/abrizer/adaptation.rb', line 43
def filepath_fragmented(output_directory)
name = "#{outfile_basename}-frag.mp4"
File.join output_directory, name
end
|
#outfile_basename ⇒ Object
34
35
36
|
# File 'lib/abrizer/adaptation.rb', line 34
def outfile_basename
"adaptation-#{width}x#{height}-#{bitrate}"
end
|
#to_hash ⇒ Object
56
57
58
|
# File 'lib/abrizer/adaptation.rb', line 56
def to_hash
{width: @width, height: @height, bitrate: @bitrate}
end
|
#to_json ⇒ Object
52
53
54
|
# File 'lib/abrizer/adaptation.rb', line 52
def to_json
MultiJson.dump(to_hash)
end
|
#to_s ⇒ Object
48
49
50
|
# File 'lib/abrizer/adaptation.rb', line 48
def to_s
"Width: #{@width}, Height: #{@height}, Bitrate: #{@bitrate}"
end
|