Class: HLS::Video::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hls.rb

Direct Known Subclasses

Dev, Web

Constant Summary collapse

PLAYLIST =
"index.m3u8".freeze
Rendition =
Data.define(:width, :height, :bitrate)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, output:) ⇒ Base

Returns a new instance of Base.



48
49
50
51
52
# File 'lib/hls.rb', line 48

def initialize(input:, output:)
  @input = Input.new(input)
  @output = output
  @renditions = []
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



42
43
44
# File 'lib/hls.rb', line 42

def input
  @input
end

#outputObject

Returns the value of attribute output.



42
43
44
# File 'lib/hls.rb', line 42

def output
  @output
end

#renditionsObject

Returns the value of attribute renditions.



42
43
44
# File 'lib/hls.rb', line 42

def renditions
  @renditions
end

Instance Method Details

#commandObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hls.rb', line 62

def command
  [
    "ffmpeg",
    "-y",
    "-i", @input.path,
    "-filter_complex", filter_complex
  ] + \
  video_maps + \
  audio_maps + \
  [
    "-f", "hls",
    "-var_stream_map", stream_map,
    "-master_pl_name", PLAYLIST,
    "-hls_time", "4",
    "-hls_playlist_type", "vod",
    "-hls_segment_filename", segment,
    playlist
  ]
end

#downscaleable_renditionsObject



54
55
56
# File 'lib/hls.rb', line 54

def downscaleable_renditions
  @renditions.select { |r| r.width <= input.width }
end

#renditionObject



58
59
60
# File 'lib/hls.rb', line 58

def rendition(...)
  @renditions << Rendition.new(...)
end