pub struct HlsOutput { /* private fields */ }Expand description
Builds and writes an HLS segmented output.
HlsOutput follows the consuming-builder pattern: each setter takes self
and returns a new Self, and the final build call validates
the configuration before returning a ready-to-write instance.
§Examples
use ff_stream::HlsOutput;
use std::time::Duration;
HlsOutput::new("/var/www/hls")
.input("source.mp4")
.segment_duration(Duration::from_secs(6))
.keyframe_interval(48)
.build()?
.write()?;Implementations§
Source§impl HlsOutput
impl HlsOutput
Sourcepub fn new(output_dir: &str) -> Self
pub fn new(output_dir: &str) -> Self
Create a new builder targeting output_dir.
The directory does not need to exist at construction time; it will be
created (if absent) by the FFmpeg HLS muxer when write
is called.
Defaults: segment duration = 6 s, keyframe interval = 48 frames.
Sourcepub fn input(self, path: &str) -> Self
pub fn input(self, path: &str) -> Self
Set the input media file path.
This is required; build will return
StreamError::InvalidConfig if no input is supplied.
Sourcepub fn segment_duration(self, d: Duration) -> Self
pub fn segment_duration(self, d: Duration) -> Self
Override the HLS segment duration (default: 6 s).
Apple’s HLS recommendation is 6 s for live streams and up to 10 s for VOD. Smaller values reduce latency but increase the number of segment files and playlist entries.
Sourcepub fn bitrate(self, bps: u64) -> Self
pub fn bitrate(self, bps: u64) -> Self
Override the target video bitrate in bits per second.
When not set, the encoder uses a default of 2 Mbit/s.
Sourcepub fn video_size(self, width: u32, height: u32) -> Self
pub fn video_size(self, width: u32, height: u32) -> Self
Override the output video dimensions.
When not set, the encoder uses the input stream’s dimensions.
Sourcepub fn keyframe_interval(self, frames: u32) -> Self
pub fn keyframe_interval(self, frames: u32) -> Self
Override the keyframe interval in frames (default: 48).
HLS requires segment boundaries to align with keyframes. Setting this to
fps × segment_duration (e.g. 24 fps × 2 s = 48) ensures clean cuts
without decoding artefacts at the start of each segment.
Sourcepub fn build(self) -> Result<Self, StreamError>
pub fn build(self) -> Result<Self, StreamError>
Validate the configuration and return a ready-to-write HlsOutput.
§Errors
StreamError::InvalidConfigwhenoutput_diris empty.StreamError::InvalidConfigwhen no input path has been set viainput.
§Examples
use ff_stream::HlsOutput;
// Missing input → error
assert!(HlsOutput::new("/tmp/hls").build().is_err());
// Valid configuration → ok
assert!(HlsOutput::new("/tmp/hls").input("src.mp4").build().is_ok());Sourcepub fn write(self) -> Result<(), StreamError>
pub fn write(self) -> Result<(), StreamError>
Write HLS segments to the output directory.
On success the output directory will contain a playlist.m3u8 file and
numbered segment files (segment000.ts, segment001.ts, …).
§Errors
StreamError::InvalidConfigwhen called without first callingbuild(i.e.input_pathisNone).StreamError::Iowhen the output directory cannot be created.StreamError::Ffmpegwhen theFFmpegHLS muxer fails.