pub struct StreamBuilder { /* private fields */ }Expand description
A builder for creating RTMP streaming sessions with a simplified API.
This builder provides a fluent interface for configuring and starting RTMP streaming without needing to manually manage the server lifecycle.
§Example
use ez_ffmpeg::rtmp::embed_rtmp_server::EmbedRtmpServer;
let handle = EmbedRtmpServer::stream_builder()
.address("localhost:1935")
.app_name("live")
.stream_key("stream1")
.input_file("video.mp4")
// readrate defaults to 1.0 (realtime)
.start()?;
handle.wait()?;Implementations§
Source§impl StreamBuilder
impl StreamBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new StreamBuilder with default settings.
By default, readrate is set to 1.0 (real-time playback speed),
which is equivalent to FFmpeg’s -re flag. This is the recommended
setting for live RTMP streaming scenarios.
Sourcepub fn address(self, address: impl Into<String>) -> Self
pub fn address(self, address: impl Into<String>) -> Self
Sets the address for the RTMP server (e.g., “localhost:1935”).
Sourcepub fn stream_key(self, stream_key: impl Into<String>) -> Self
pub fn stream_key(self, stream_key: impl Into<String>) -> Self
Sets the stream key (publishing name).
Sourcepub fn input_file(self, path: impl AsRef<Path>) -> Self
pub fn input_file(self, path: impl AsRef<Path>) -> Self
Sets the input file path to stream.
Sourcepub fn readrate(self, rate: f32) -> Self
pub fn readrate(self, rate: f32) -> Self
Sets the read rate for the input file.
A value of 1.0 means realtime playback speed. This is useful for simulating live streaming from a file.
Sourcepub fn gop_limit(self, limit: usize) -> Self
pub fn gop_limit(self, limit: usize) -> Self
Sets the GOP (Group of Pictures) limit for the RTMP server.
This controls how many GOPs are buffered for new subscribers.
Sourcepub fn max_connections(self, max: usize) -> Self
pub fn max_connections(self, max: usize) -> Self
Sets the maximum number of connections the server will accept.
Sourcepub fn start(self) -> Result<StreamHandle, StreamError>
pub fn start(self) -> Result<StreamHandle, StreamError>
Starts the RTMP streaming session.
This method validates all required parameters, starts the RTMP server, and begins streaming the input file.
§Required Parameters
address: The server addressapp_name: The RTMP application namestream_key: The stream key (publishing name)input_file: The file to stream
§Returns
A StreamHandle that can be used to wait for completion or manage the stream.
§Errors
Returns StreamError if:
- Any required parameter is missing
- The input file does not exist
- The server fails to start
- FFmpeg context creation fails