pub struct VideoEncoder { /* private fields */ }Expand description
Stateful hardware encoder session for H.264 High or H.265 Main.
One encoder owns a private Vulkan Video encode session, per-slot NV12 input
pictures, and the RGBA→NV12 conversion on the selected Engine’s queues.
Frames enter as packed RGBA8 bytes sized exactly
visible_extent().width * visible_extent().height * 4; conversion, GOP
cadence, rate control, DPB management, and Annex-B framing stay private.
Every emitted EncodedVideoPacket is one access unit; keyframe packets
carry the session’s cached SPS/PPS (and VPS for H.265) parameter sets so
each random-access point is self-describing.
encode waits for the submitted frame and returns its packet. flush
waits for every outstanding encode job and drains the remainder — required
before close when asynchronous submissions left frames in flight.
Implementations§
Source§impl VideoEncoder
impl VideoEncoder
Sourcepub fn new(engine: &Engine, settings: VideoEncodeConfig) -> Result<Self>
pub fn new(engine: &Engine, settings: VideoEncodeConfig) -> Result<Self>
Create a session admitted by exact capability preflight.
Settings are validated against the engine’s queried encode capabilities;
session creation then performs the Vulkan-level admission a second time.
A device without an encode queue family for the requested codec profile
fails here, not on the first encode call.
§Errors
Returns an error when settings fail preflight or the engine’s device does not admit a hardware encode session for the profile.
Sourcepub fn encode(
&mut self,
rgba: &[u8],
presentation_timestamp_micros: u64,
) -> Result<EncodedVideoPacket>
pub fn encode( &mut self, rgba: &[u8], presentation_timestamp_micros: u64, ) -> Result<EncodedVideoPacket>
Encode one packed RGBA8 frame and return its access unit.
rgba must contain exactly
visible_extent().width * visible_extent().height * 4 bytes in
row-major RGBA8 order. The frame is converted to the session’s coded
NV12 extent, queued on the hardware encode queue, and awaited before the
packet is returned; presentation timestamps are in microseconds.
§Errors
Returns an error after close, for a mismatched input size, or when conversion, encode submission, feedback, or bitstream readback fails.
Sourcepub fn encode_rgba16(
&mut self,
rgba: &[u16],
presentation_timestamp_micros: u64,
) -> Result<EncodedVideoPacket>
pub fn encode_rgba16( &mut self, rgba: &[u16], presentation_timestamp_micros: u64, ) -> Result<EncodedVideoPacket>
Encode one packed RGBA64 frame and return its access unit.
rgba must contain exactly
visible_extent().width * visible_extent().height * 4 little-endian
16-bit samples in row-major RGBA order; the session must carry a
wide-component profile such as H.265 Main10. An 8-bit session rejects
the input through its length validation.
§Errors
Returns an error after close, for a mismatched input size, or when conversion, encode submission, feedback, or bitstream readback fails.
Sourcepub fn flush(&mut self) -> Result<Vec<EncodedVideoPacket>>
pub fn flush(&mut self) -> Result<Vec<EncodedVideoPacket>>
Wait for every outstanding encode job and drain all remaining packets.
Synchronous encode leaves nothing pending; flush is the
tail drain for asynchronous submissions and returns an empty list when
the session is already drained.
§Errors
Returns an error after close or when an outstanding job fails feedback or bitstream readback.
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Close the encoder and release its session resources.
Unharvested asynchronous jobs are released without being drained;
call flush first to keep every submitted frame.
Sourcepub fn coded_extent(&self) -> Option<VideoExtent>
pub fn coded_extent(&self) -> Option<VideoExtent>
Return the aligned NV12 coded extent the driver encodes at.
Sourcepub fn visible_extent(&self) -> Option<VideoExtent>
pub fn visible_extent(&self) -> Option<VideoExtent>
Return the visible input extent expected by encode.
Sourcepub fn codec_headers(&self) -> Option<&[u8]>
pub fn codec_headers(&self) -> Option<&[u8]>
Borrow the session’s cached codec parameter sets in Annex-B form.
H.264 sessions carry SPS+PPS and H.265 sessions carry VPS+SPS+PPS; the bytes are already prepended to every keyframe packet, so muxers that need out-of-band codec configuration should derive it from a keyframe or use this reference directly.
Sourcepub fn record_frames(&mut self, frames: &[(&[u8], u64)]) -> Result<()>
pub fn record_frames(&mut self, frames: &[(&[u8], u64)]) -> Result<()>
Record RGBA8 frame encodes into an active execution capture.
Inside Engine::capture this opens a retained session, records each
frame’s RGBA→native conversion on the compute family and its
vkCmdEncodeVideoKHR picture on the encode family as execution-graph
nodes, and restores this encoder’s live session afterwards. The
resulting plan replays the same frames without host work; packets
materialize from the plan’s completion Event through
Event::encoded_packets.
Returns an error outside capture, after close, for an empty frame list,
or when a frame’s length does not match visible_extent().
Sourcepub fn record_planes(&mut self, frames: &[(&[Matrix], u64)]) -> Result<()>
pub fn record_planes(&mut self, frames: &[(&[Matrix], u64)]) -> Result<()>
Record one frame whose input planes are already engine matrices.
Each entry supplies the session’s native-format planes in order (Y
then UV for NV12/P010) plus a presentation timestamp in microseconds.
Inside Engine::capture, each frame’s buffer→image staging records
on the compute family and its vkCmdEncodeVideoKHR picture on the
encode family, so a decoded-and-transformed oa::Matrix plane can be
re-encoded without a host round trip.
Returns an error outside capture, after close, for an empty frame list, or when a frame’s plane count or extent mismatches the session.