pub struct LiveGstreamerEncoder {
config: EncoderConfig,
video_intermediate_path: PathBuf,
audio_scratch_path: PathBuf,
video_child: Child,
video_stdin: Option<ChildStdin>,
stderr_drain: Option<JoinHandle<String>>,
audio_writer: BufWriter<File>,
expected_video_bytes_per_frame: usize,
frames_pushed: u64,
audio_chunks_pushed: u64,
}Expand description
Live (streaming) video encoder. Spawns the encode pipeline up front
and streams BGRA frames into its stdin, so the only video on disk
during capture is already compressed. That bounds the scratch
footprint to the encoded bitrate instead of the raw firehose
(width × height × 4 × fps ≈ 250 MB/s at 1080p, >1 GB/s at Retina)
— the prerequisite for capturing at native resolution.
Audio is still buffered to a small raw .f32.scratch (≈0.4 MB/s)
and muxed in at finalize via
build_remux_args (the video leg is stream-copied, not
re-encoded). Keeping audio out of the live pipeline lets the
recorder feed a single fd (stdin) with no extra fd plumbing.
Real recording is macOS-only; the pipeline strings are cross-OS so
the unit tests + clippy pass everywhere, but the spawn only
succeeds where the encoder element + gst-launch-1.0 exist.
Fields§
§config: EncoderConfig§video_intermediate_path: PathBufCompressed video-only intermediate the live child writes to. Remuxed with audio at finalize, then deleted.
audio_scratch_path: PathBufRaw F32LE audio scratch — encoded to the container codec at finalize.
video_child: ChildThe live gst-launch-1.0 child (stdin → intermediate).
video_stdin: Option<ChildStdin>Write end of the child’s stdin; None once finalize closes it.
stderr_drain: Option<JoinHandle<String>>Drains the child’s stderr on a side thread so a chatty pipeline can’t deadlock on a full stderr pipe; joined at finalize for diagnostics.
audio_writer: BufWriter<File>§expected_video_bytes_per_frame: usize§frames_pushed: u64§audio_chunks_pushed: u64Implementations§
Source§impl LiveGstreamerEncoder
impl LiveGstreamerEncoder
Sourcepub fn new(config: EncoderConfig) -> Result<Self, EncodeError>
pub fn new(config: EncoderConfig) -> Result<Self, EncodeError>
Spawn the live video-encode pipeline + open the audio scratch.
§Errors
EncodeError::InvalidConfig— any of width / height / framerate / channels / sample_rate is zero.EncodeError::Unsupported— no encoder wired for (format, OS).EncodeError::Spawn—gst-launch-1.0missing from PATH.EncodeError::Io— the audio scratch can’t be created.
Sourcepub fn frames_pushed(&self) -> u64
pub fn frames_pushed(&self) -> u64
Frame count pushed so far.
Sourcepub fn audio_chunks_pushed(&self) -> u64
pub fn audio_chunks_pushed(&self) -> u64
Audio chunks pushed so far.
Sourcepub fn config(&self) -> &EncoderConfig
pub fn config(&self) -> &EncoderConfig
Borrow the resolved encoder config.
Trait Implementations§
Source§impl Debug for LiveGstreamerEncoder
impl Debug for LiveGstreamerEncoder
Source§impl Drop for LiveGstreamerEncoder
impl Drop for LiveGstreamerEncoder
Source§impl VideoEncoder for LiveGstreamerEncoder
impl VideoEncoder for LiveGstreamerEncoder
Source§fn push_video_frame(
&mut self,
bgra: &[u8],
_pts: Duration,
) -> Result<(), EncodeError>
fn push_video_frame( &mut self, bgra: &[u8], _pts: Duration, ) -> Result<(), EncodeError>
bgra.len() must equal width * height * 4. Read moreSource§fn push_audio_chunk(
&mut self,
samples: &[f32],
_pts: Duration,
) -> Result<(), EncodeError>
fn push_audio_chunk( &mut self, samples: &[f32], _pts: Duration, ) -> Result<(), EncodeError>
[ch0, ch1, ch0, ch1, ...] for stereo. Read more