pub struct LiveHlsOutput { /* private fields */ }Expand description
Live HLS output: receives frames and writes a sliding-window .m3u8 playlist.
Build with LiveHlsOutput::new, chain setter methods, then call
build to open the FFmpeg contexts. After build():
push_videoandpush_audioencode and mux frames in real time.crate::StreamOutput::finishflushes all encoders and writes the HLS trailer.
The output directory is created automatically by build() if it does not exist.
Implementations§
Source§impl LiveHlsOutput
impl LiveHlsOutput
Sourcepub fn segment_duration(self, duration: Duration) -> Self
pub fn segment_duration(self, duration: Duration) -> Self
Set the target HLS segment duration.
Default: 6 seconds.
Sourcepub fn playlist_size(self, size: u32) -> Self
pub fn playlist_size(self, size: u32) -> Self
Set the maximum number of segments kept in the sliding-window playlist.
Default: 5.
Sourcepub fn segment_format(self, fmt: HlsSegmentFormat) -> Self
pub fn segment_format(self, fmt: HlsSegmentFormat) -> Self
Set the HLS segment container format (default: HlsSegmentFormat::Ts).
Use HlsSegmentFormat::Fmp4 to produce CMAF-compatible fMP4 segments
(.m4s) with an init.mp4 initialization segment.
Sourcepub fn build(self) -> Result<Self, StreamError>
pub fn build(self) -> Result<Self, StreamError>
Open all FFmpeg contexts and write the HLS header.
§Errors
Returns StreamError::InvalidConfig when:
output_diris empty.videowas not called beforebuild.
Returns StreamError::Io when the output directory cannot be created.
Returns StreamError::Ffmpeg when any FFmpeg operation fails.
Source§impl LiveHlsOutput
impl LiveHlsOutput
Sourcepub fn video(self, width: u32, height: u32, fps: f64) -> Self
pub fn video(self, width: u32, height: u32, fps: f64) -> Self
Set the video encoding parameters (width, height, fps).
This method must be called before build.
Sourcepub fn audio(self, sample_rate: u32, channels: u32) -> Self
pub fn audio(self, sample_rate: u32, channels: u32) -> Self
Enable audio output with the given sample rate and channel count.
If this method is not called, audio is disabled.
Sourcepub fn video_codec(self, codec: VideoCodec) -> Self
pub fn video_codec(self, codec: VideoCodec) -> Self
Set the video codec.
Default: VideoCodec::H264.
Sourcepub fn audio_codec(self, codec: AudioCodec) -> Self
pub fn audio_codec(self, codec: AudioCodec) -> Self
Set the audio codec.
Default: AudioCodec::Aac.
Sourcepub fn video_bitrate(self, bitrate: u64) -> Self
pub fn video_bitrate(self, bitrate: u64) -> Self
Set the video encoder target bit rate in bits/s.
Sourcepub fn audio_bitrate(self, bitrate: u64) -> Self
pub fn audio_bitrate(self, bitrate: u64) -> Self
Set the audio encoder target bit rate in bits/s.
Default: 128 000 (128 kbit/s).