Skip to main content

HlsOutput

Struct HlsOutput 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<Self, StreamError>

Validate the configuration and return a ready-to-write HlsOutput.

§Errors
§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());
Source

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.