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
impl VideoRecorder
Sourcepub fn new(engine: &Engine, config: VideoRecorderConfig) -> Result<Self>
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.
Sourcepub fn write_rgba(&mut self, rgba: &[u8], pts_micros: u64) -> Result<()>
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.
Sourcepub fn write_audio(
&mut self,
interleaved: &[f32],
sample_rate: u32,
channel_count: u32,
pts_micros: u64,
) -> Result<()>
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.
Sourcepub fn write_audio_chunk(&mut self, chunk: &AudioCaptureChunk) -> Result<()>
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.
Sourcepub fn finalize(&mut self) -> Result<()>
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.
Sourcepub fn close(&mut self)
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.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Return the number of video frames submitted for encode.
Sourcepub const fn config(&self) -> &VideoRecorderConfig
pub const fn config(&self) -> &VideoRecorderConfig
Return the active configuration.