Skip to main content

VideoRecorder

Struct VideoRecorder 

Source
pub struct VideoRecorder { /* private fields */ }
Expand description

Stateful streaming MP4 recorder for hardware-encoded H.264/H.265 video.

write_rgba submits one packed RGBA8 frame asynchronously and muxes every packet the slot ring has completed; finalize drains the remaining encoder jobs and closes the container. Audio chunks arriving before the first video frame are buffered until the first video presentation timestamp establishes the shared timeline.

Implementations§

Source§

impl VideoRecorder

Source

pub fn new(engine: &Engine, config: VideoRecorderConfig) -> Result<Self>

Create a recorder, its encoder session, and the output container.

The encode profile must carry a non-zero extent admitted by the engine’s queried encode capabilities; audio, when configured, admits only the muxer’s PCM-S16 track.

§Errors

Returns an error for an empty output path or zero extent, when the device does not admit the encode session, when the audio profile is not PCM-S16, or when the container cannot be created.

Source

pub fn write_rgba(&mut self, rgba: &[u8], pts_micros: u64) -> Result<()>

Submit one packed RGBA8 frame and mux every packet now complete.

rgba must contain exactly encode.width * encode.height * 4 bytes. The encode job runs asynchronously on the session’s slot ring; packets are muxed in submission order while finalize drains the tail.

§Errors

Returns an error after close or finalize, for a mismatched input size, or when submission, feedback, or muxing fails.

Source

pub fn write_audio( &mut self, interleaved: &[f32], sample_rate: u32, channel_count: u32, pts_micros: u64, ) -> Result<()>

Append captured interleaved F32 audio aligned to the video timeline.

Sample format must match the configured audio profile. Chunks received before the first video frame are retained until the first video presentation timestamp arrives; gaps are filled with silence and overlapping samples are trimmed.

§Errors

Returns an error after close or finalize, when audio is not enabled, for a mismatched sample format or incomplete frames, or when encoding or muxing fails.

Source

pub fn write_audio_chunk(&mut self, chunk: &AudioCaptureChunk) -> Result<()>

Append one capture chunk through write_audio.

§Errors

Returns an error under the same conditions as write_audio.

Source

pub fn finalize(&mut self) -> Result<()>

Drain the encoder, flush pending audio, and finalize the container.

Idempotent: a second call returns Ok(()). A recording with no muxed frame cannot be finalized — the file would carry a header and no samples.

§Errors

Returns an error after close, when any outstanding encode job fails, or when the container trailer cannot be written.

Source

pub fn close(&mut self)

Abandon the recording and release encoder, muxer, and host state.

Closing an unfinished recording never writes a movie trailer; the output file remains at whatever was muxed so far. Call finalize first when the recording is required.

Source

pub fn is_open(&self) -> bool

Return whether the recorder still accepts video and audio input.

Source

pub fn frame_count(&self) -> u64

Return the number of video frames submitted for encode.

Source

pub const fn config(&self) -> &VideoRecorderConfig

Return the active configuration.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.