Class: HLS::Manifest::Variant
- Inherits:
-
Object
- Object
- HLS::Manifest::Variant
- Defined in:
- lib/hls/manifest.rb
Overview
A single rendition variant — its ordered list of segments and the ability to slice a duration window for previews.
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#variant_path ⇒ Object
readonly
Returns the value of attribute variant_path.
Instance Method Summary collapse
-
#[](range) ⇒ Object
Slice a duration window.
-
#duration ⇒ Object
Duration in seconds.
-
#initialize(manifest:, variant_path:, items:) ⇒ Variant
constructor
A new instance of Variant.
-
#playlist ⇒ Object
The variant playlist with each segment rewritten to a pre-signed URL.
Constructor Details
#initialize(manifest:, variant_path:, items:) ⇒ Variant
Returns a new instance of Variant.
151 152 153 154 155 |
# File 'lib/hls/manifest.rb', line 151 def initialize(manifest:, variant_path:, items:) @manifest = manifest @variant_path = variant_path @items = items end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
149 150 151 |
# File 'lib/hls/manifest.rb', line 149 def items @items end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
149 150 151 |
# File 'lib/hls/manifest.rb', line 149 def manifest @manifest end |
#variant_path ⇒ Object (readonly)
Returns the value of attribute variant_path.
149 150 151 |
# File 'lib/hls/manifest.rb', line 149 def variant_path @variant_path end |
Instance Method Details
#[](range) ⇒ Object
Slice a duration window. The range is in seconds. Inclusive ranges round down, exclusive ranges round up. Useful for preview windows (e.g. ‘variant` for a 30-second teaser).
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/hls/manifest.rb', line 167 def [](range) raise ArgumentError, "Only Range objects are supported" unless range.is_a?(Range) segment_count = if range.exclude_end? (range.end.to_f / manifest.segment_duration).ceil else (range.end.to_f / manifest.segment_duration).floor end Variant.new(manifest: manifest, variant_path: variant_path, items: items.take(segment_count)) end |
#duration ⇒ Object
Duration in seconds. Approximate — uses segment_duration as a uniform per-segment value, which matches how ffmpeg writes VOD bundles. The last segment may be slightly shorter.
160 161 162 |
# File 'lib/hls/manifest.rb', line 160 def duration items.count * manifest.segment_duration end |
#playlist ⇒ Object
The variant playlist with each segment rewritten to a pre-signed URL. Returns a fresh M3u8::Playlist; does not mutate ‘items`.
182 183 184 185 186 187 188 189 190 |
# File 'lib/hls/manifest.rb', line 182 def playlist list = M3u8::Playlist.new list.items = items.map do |item| signed = item.clone signed.segment = manifest.presigned_url(variant_path, item.segment) signed end list end |