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():
push_videoandpush_audioencode and transmit frames in real time.StreamOutput::finishflushes all encoders, sends the FLV end-of-stream marker, and closes the RTMP connection.
RTMP/FLV requires H.264 video and AAC audio; build returns
StreamError::UnsupportedCodec for any other codec selection.
Implementations§
Source§impl RtmpOutput
impl RtmpOutput
Sourcepub fn new(url: &str) -> Self
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");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.
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. Only H264 is accepted by
build; any other value returns
StreamError::UnsupportedCodec.
Sourcepub fn audio_codec(self, codec: AudioCodec) -> Self
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.
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.
Default: 4 000 000 (4 Mbit/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).
Sourcepub fn build(self) -> Result<Self, StreamError>
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://. 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).