Recording and the replay buffer must work whether or not a stream is live, and neither may cost a second encode, so both are fed the packets the streamer's encoders already produce. That makes them output sinks over one small trait rather than pipelines of their own. The container is an own EBML writer: Matroska and WebM need so little of the format for this (a header, one Info, one Tracks, clusters of SimpleBlocks) that a dependency would be the larger cost. The segment size stays unknown and there are no cues, so a recording cut short by a crash still plays; only the duration is written back at the end, because a file of unknown length is a poor thing to hand a player. H.264 is stored the way Matroska wants it, length-prefixed with its parameter sets in CodecPrivate, which is why the header waits for the first keyframe. The replay buffer keeps whole keyframe groups so a clip always starts where a decoder can, and a window longer than memory allows spills its oldest packets to a temporary file it drops again once they age out -- the length is a setting with no maximum, so it cannot be bounded by what fits in RAM. RTMP is a seam that says what it is waiting for (the muxing side of the FFmpeg loader) instead of dropping a stream silently. tests/studio_record.rs runs real VP8 frames through both and reads the files back with ffprobe: codecs, size, duration, and every frame of a clip decoded. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
72 lines
2.1 KiB
Rust
72 lines
2.1 KiB
Rust
//! RTMP: the seam only.
|
|
//!
|
|
//! RTMP will go out through the FFmpeg libraries the crate already loads at
|
|
//! runtime ([`crate::ffmpeg`]): `libavformat` speaks `rtmp://` and
|
|
//! `rtmps://`, so the studio will hand it the same encoded packets it hands
|
|
//! every other output and never link or ship an RTMP stack of its own.
|
|
//!
|
|
//! What is missing is the muxer side of that loader (`avformat_alloc_output_
|
|
//! context2`, `av_interleaved_write_frame` and the bitstream filters H.264
|
|
//! and AAC need in FLV). Until then [`Rtmp::connect`] says so rather than
|
|
//! pretending, so a scene file or a `voelinctl` command that names an RTMP
|
|
//! output fails with a reason instead of silently dropping the stream.
|
|
|
|
use crate::studio::output::{OutputSink, Packet, Track};
|
|
use crate::{Error, Result};
|
|
|
|
/// An RTMP output. Not implemented yet; see the [module docs](self).
|
|
#[derive(Debug)]
|
|
pub struct Rtmp {
|
|
url: String,
|
|
}
|
|
|
|
impl Rtmp {
|
|
/// Whether `url` is one this output would take.
|
|
pub fn handles(url: &str) -> bool {
|
|
url.starts_with("rtmp://") || url.starts_with("rtmps://")
|
|
}
|
|
|
|
/// Always fails for now, with what is missing.
|
|
pub fn connect(url: &str, _key: Option<&str>) -> Result<Self> {
|
|
Err(Error::CodecUnavailable {
|
|
codec: crate::codec::Codec::H264,
|
|
reason: format!(
|
|
"RTMP ({url}) needs the muxing side of the FFmpeg loader, which is not \
|
|
written yet; record to a file or use WHIP"
|
|
),
|
|
})
|
|
}
|
|
|
|
pub fn url(&self) -> &str {
|
|
&self.url
|
|
}
|
|
}
|
|
|
|
impl OutputSink for Rtmp {
|
|
fn name(&self) -> &str {
|
|
&self.url
|
|
}
|
|
|
|
fn wants(&self, _track: Track) -> bool {
|
|
true
|
|
}
|
|
|
|
fn write(&mut self, _packet: &Packet<'_>) -> Result<()> {
|
|
Err(Error::Capture { backend: "rtmp", message: "RTMP is not implemented".into() })
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn rtmp_urls_are_recognised_but_refused() {
|
|
assert!(Rtmp::handles("rtmp://live.example/app"));
|
|
assert!(Rtmp::handles("rtmps://live.example/app"));
|
|
assert!(!Rtmp::handles("https://example/whip"));
|
|
let e = Rtmp::connect("rtmp://live.example/app", Some("key")).unwrap_err().to_string();
|
|
assert!(e.contains("FFmpeg"), "{e}");
|
|
}
|
|
}
|