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>