HLX.Writer
(HLS Reader and Writer v0.6.0)
View Source
Module for writing HLS master and media playlists.
Summary
Functions
Adds a discontinuity to the playlist.
Add a new rendition to the master playlist.
Same as add_rendition/3, but raises an error if the operation fails.
Add a new variant to the master playlist.
Same as add_variant/3, but raises an error if the operation fails.
Closes the writer.
Creates a new HLS writer.
Same as new/1, but raises an error if the operation fails.
Writes a sample to the specified variant or rendition.
Types
@type mode() :: :live | :vod
@type rendition_opts() :: [ type: :audio, track: HLX.Track.t(), group_id: String.t(), default: boolean(), auto_select: boolean() ]
@type segment_type() :: :mpeg_ts | :fmp4 | :low_latency
@opaque t()
@type tracks() :: [HLX.Track.t()]
@type variant_opts() :: [tracks: [HLX.Track.t()], audio: String.t()]
Functions
Adds a discontinuity to the playlist.
This flushes any pending segments, so make sure all the samples are written before
and adds a discontinuity to the specified variant or to all variants if no
variant_id is provided.
@spec add_rendition(t(), String.t(), rendition_opts()) :: {:ok, t()} | {:error, any()}
Add a new rendition to the master playlist.
This adds a new EXT-X-MEDIA entry to the master playlist.
The name should be unique across variants and renditions and it's used as the name of
the playlist (name.m3u8).
The following parameter may be provided:
type- [Required] The type should always be:audiosince it's the only supported media type.track- [Required] The track that defines the media.group_id- [Required] The group id of the rendition.default- A boolean indicating if this is the default rendition.auto_select- A boolean setting the auto select.
@spec add_rendition!(t(), String.t(), rendition_opts()) :: t()
Same as add_rendition/3, but raises an error if the operation fails.
@spec add_variant(t(), String.t(), variant_opts()) :: {:ok, t()} | {:error, any()}
Add a new variant to the master playlist.
This adds a new EXT-X-STREAM-INF entry to the master playlist.
The name should be unique across variants and renditions and it's used as the name of
the playlist (<name>.m3u8).
The following parameter may be provided:
tracks- [Required] One or more tracks definitions, all the media are muxed in the same segment.audio- Reference to agroup_idof a rendition.
@spec add_variant!(t(), String.t(), variant_opts()) :: t()
Same as add_variant/3, but raises an error if the operation fails.
@spec close(t()) :: :ok
Closes the writer.
Closes the writer and flush any pending segments. if the mode is vod creates the final
playlists.
Creates a new HLS writer.
The following options can be provided:
type- The type of the playlist, either:masteror:media. Defaults to:media.mode- The mode of the playlist, either:liveor:vod. Defaults to:live.segment_type- The type of segments to generate, either:mpeg_ts,:fmp4or:low_latency. Defaults to:fmp4.max_segments- The maximum number of segments to keep in the playlist, ignored onvodmode. Defaults to 0 (no limit).storage_dir- The directory where to store the playlists and segments. This is required.segment_duration- The target duration of each segment in milliseconds. Defaults to 2000.part_duration- The target duration of each part in milliseconds (only for low-latency segments). Defaults to 300.server_control- A keyword list with server control options:can_block_reload- A boolean indicating if the server support blocking manifest reload until a certain segment/part is available. Defaults tofalse.
You can provide callbacks for segment and part creation by adding the following options:
on_segment_created- A 2-arity function that will be called when a new segment is created. The fuction receives two arguments: the variant id and the segment info.on_part_created- A 2-arity function that will be called when a new part is created. The fuction receives two arguments: the variant id and the part info.
Same as new/1, but raises an error if the operation fails.
@spec write_sample(t(), String.t(), HLX.Sample.t()) :: t()
Writes a sample to the specified variant or rendition.