Skip to main content

LiveGstreamerEncoder

Struct LiveGstreamerEncoder 

Source
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: PathBuf

Compressed video-only intermediate the live child writes to. Remuxed with audio at finalize, then deleted.

§audio_scratch_path: PathBuf

Raw F32LE audio scratch — encoded to the container codec at finalize.

§video_child: Child

The 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: u64

Implementations§

Source§

impl LiveGstreamerEncoder

Source

pub fn new(config: EncoderConfig) -> Result<Self, EncodeError>

Spawn the live video-encode pipeline + open the audio scratch.

§Errors
Source

pub fn frames_pushed(&self) -> u64

Frame count pushed so far.

Source

pub fn audio_chunks_pushed(&self) -> u64

Audio chunks pushed so far.

Source

pub fn config(&self) -> &EncoderConfig

Borrow the resolved encoder config.

Trait Implementations§

Source§

impl Debug for LiveGstreamerEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LiveGstreamerEncoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl VideoEncoder for LiveGstreamerEncoder

Source§

fn push_video_frame( &mut self, bgra: &[u8], _pts: Duration, ) -> Result<(), EncodeError>

Push one BGRA frame at the given monotonic PTS (measured from session start). bgra.len() must equal width * height * 4. Read more
Source§

fn push_audio_chunk( &mut self, samples: &[f32], _pts: Duration, ) -> Result<(), EncodeError>

Push interleaved F32LE audio samples at the given PTS. Sample layout is [ch0, ch1, ch0, ch1, ...] for stereo. Read more
Source§

fn finalize(self: Box<Self>) -> Result<PathBuf, EncodeError>

Finalize: spawn the gst-launch pipeline that consumes the scratch files and writes the final container at the configured output path. Consumes self because the encoder is single-use. 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more