Skip to main content

SrtOutput

Struct SrtOutput 

Source
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_video and push_audio encode and transmit frames in real time.
  • crate::StreamOutput::finish flushes 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

Source

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");
Source

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://.
  • video was not called before build.

Returns StreamError::UnsupportedCodec when:

Returns StreamError::Ffmpeg when any FFmpeg operation fails (including network connection errors).

Source§

impl SrtOutput

Source

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.

Source

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).

Source

pub fn video_codec(self, codec: VideoCodec) -> Self

Set the video codec.

Default: VideoCodec::H264.

Source

pub fn audio_codec(self, codec: AudioCodec) -> Self

Set the audio codec.

Default: AudioCodec::Aac.

Source

pub fn video_bitrate(self, bitrate: u64) -> Self

Set the video encoder target bit rate in bits/s.

Source

pub fn audio_bitrate(self, bitrate: u64) -> Self

Set the audio encoder target bit rate in bits/s.

Default: 128 000 (128 kbit/s).

Trait Implementations§

Source§

impl StreamOutput for SrtOutput

Source§

fn push_video(&mut self, frame: &VideoFrame) -> Result<(), StreamError>

Push one video frame into the stream.
Source§

fn push_audio(&mut self, frame: &AudioFrame) -> Result<(), StreamError>

Push one audio frame into the stream.
Source§

fn finish(self: Box<Self>) -> Result<(), StreamError>

Flush all buffered data and close the output. Read more

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.