Skip to main content

RtmpOutput

Struct RtmpOutput 

Source
pub struct RtmpOutput { /* private fields */ }
Expand description

Live RTMP output: encodes frames and pushes them to an RTMP ingest endpoint.

Build with RtmpOutput::new, chain setter methods, then call build to open the FFmpeg context and establish the RTMP connection. After build():

RTMP/FLV requires H.264 video and AAC audio; build returns StreamError::UnsupportedCodec for any other codec selection.

Implementations§

Source§

impl RtmpOutput

Source

pub fn new(url: &str) -> Self

Create a new builder that streams to the given RTMP URL.

The URL must begin with rtmp://; build returns StreamError::InvalidConfig otherwise.

§Example
use ff_stream::RtmpOutput;

let out = RtmpOutput::new("rtmp://ingest.example.com/live/key");
Source

pub fn video(self, width: u32, height: u32, fps: f64) -> Self

Set the video encoding parameters.

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. Only H264 is accepted by build; any other value returns StreamError::UnsupportedCodec.

Source

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

Set the audio codec.

Default: AudioCodec::Aac. Only Aac is accepted by build; any other value returns StreamError::UnsupportedCodec.

Source

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

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

Default: 4 000 000 (4 Mbit/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).

Source

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

Open the FFmpeg context and establish the RTMP connection.

§Errors

Returns StreamError::InvalidConfig when:

  • The URL does not start with rtmp://.
  • video was not called before build.

Returns StreamError::UnsupportedCodec when:

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

Trait Implementations§

Source§

impl StreamOutput for RtmpOutput

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.