pub struct SrtOutput { /* private fields */ }Expand description
Live SRT output: encodes frames as MPEG-TS and pushes them to an SRT destination.
Build with SrtOutput::new, chain setter methods, then call
build to open the FFmpeg context and establish the SRT
connection. After build():
push_videoandpush_audioencode and transmit frames in real time.crate::StreamOutput::finishflushes all encoders, writes the MPEG-TS end-of-stream, and closes the SRT connection.
The SRT transport uses MPEG-TS as the container (H.264 video + AAC audio).
build returns StreamError::UnsupportedCodec for any
other codec selection.
build also performs a runtime check and returns
StreamError::ProtocolUnavailable when the linked FFmpeg library was
built without libsrt support.
Implementations§
Source§impl SrtOutput
impl SrtOutput
Sourcepub fn new(url: &str) -> Self
pub fn new(url: &str) -> Self
Create a new builder that streams to the given SRT URL.
The URL must begin with srt://; build returns
StreamError::InvalidConfig otherwise.
§Example
use ff_stream::SrtOutput;
let out = SrtOutput::new("srt://192.168.1.100:9000");Sourcepub fn build(self) -> Result<Self, StreamError>
pub fn build(self) -> Result<Self, StreamError>
Open the FFmpeg MPEG-TS context and establish the SRT connection.
§Errors
Returns StreamError::ProtocolUnavailable when the linked FFmpeg
was built without libsrt support.
Returns StreamError::InvalidConfig when:
- The URL does not start with
srt://. videowas not called beforebuild.
Returns StreamError::UnsupportedCodec when:
- The video codec is not
VideoCodec::H264. - The audio codec is not
AudioCodec::Aac.
Returns StreamError::Ffmpeg when any FFmpeg operation fails
(including network connection errors).
Source§impl SrtOutput
impl SrtOutput
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
Set the audio sample rate and channel count.
Defaults: 44 100 Hz, 2 channels (stereo).
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).