pub struct Encoder { /* private fields */ }Expand description
Video encoder. Build one with Encoder::new, feed it raw RGBA frames via
encode_rgba, and publish the resulting packets through
a Producer built for the same Codec.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
The resolution this encoder emits, which every frame fed to it must match.
Sourcepub fn bitrate(&self) -> u64
pub fn bitrate(&self) -> u64
The current target bitrate in bits per second: what
Config::bitrate resolved to at open, or the last value
set_bitrate accepted.
Sourcepub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
pub fn set_bitrate(&mut self, bitrate: u64) -> Result<(), Error>
Retune the live encoder to bitrate bits per second, taking effect from
roughly the next frame. No IDR is forced, so this is cheap enough to
drive from a congestion controller: pair it with
rate::Control, which decides when the target
is worth moving.
Setting the rate the encoder is already at does nothing and succeeds.
§Errors
Returns Error::BitrateUnsupported if this backend can’t retune while
running. That’s not fatal: the encoder keeps running at its current rate,
so a caller driving a control loop should stop adapting rather than stop
encoding.
Sourcepub fn codec(&self) -> Codec
pub fn codec(&self) -> Codec
The codec this encoder emits. A Producer must be
built for the same codec to publish its packets.
Sourcepub fn encode_rgba(
&mut self,
rgba: &[u8],
size: Size,
keyframe: bool,
) -> Result<Vec<Bytes>, Error>
pub fn encode_rgba( &mut self, rgba: &[u8], size: Size, keyframe: bool, ) -> Result<Vec<Bytes>, Error>
Encode one tightly-packed RGBA frame of size, returning zero or more
encoded packets in the codec’s framing. Set keyframe to force an IDR
(e.g. on resume so a re-subscribing viewer can start decoding at once).
size must equal the encoder’s size, and rgba must hold
exactly width * height * 4 bytes with no row padding.
Sourcepub fn encode_i420(
&mut self,
i420: &[u8],
size: Size,
keyframe: bool,
) -> Result<Vec<Bytes>, Error>
pub fn encode_i420( &mut self, i420: &[u8], size: Size, keyframe: bool, ) -> Result<Vec<Bytes>, Error>
Encode one tightly-packed I420 frame of size (Y then U then V, no row
padding, BT.601 limited range), returning zero or more encoded packets in
the codec’s framing. Set keyframe to force an IDR.
size must equal the encoder’s size, and i420 must hold
exactly width * height * 3 / 2 bytes.
The bring-your-own-I420 path, which copies the buffer to take ownership of
it. A transcoder should prefer encode: it takes a decoded
frame directly and keeps a GPU one on the GPU, so it neither copies nor
round-trips through system memory.
Sourcepub fn encode(
&mut self,
frame: &Surface,
keyframe: bool,
) -> Result<Vec<Bytes>, Error>
pub fn encode( &mut self, frame: &Surface, keyframe: bool, ) -> Result<Vec<Bytes>, Error>
Encode a Surface, whether it came from capture or a
decoder (the transcode input path).
A GPU surface feeds a hardware encoder on the same device directly
(NVDEC -> NVENC never leaves the GPU, a CVPixelBuffer goes straight to
VideoToolbox); anything else falls back to a CPU I420 upload. The surface
must already be at the encoder’s resolution: decode with
decode::Config::resize, or scale first with
decode::Frame::resize.