pub struct Encoder { /* private fields */ }Expand description
An OpenH264 encoder.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Create an encoder with default settings.
The width and height will be taken from the YUVSource when calling Encoder::encode().
This method is only available when compiling with the source feature.
§Errors
This should never error, but the underlying OpenH264 encoder has an error indication and since we don’t know their code that well we just can’t guarantee it.
Sourcepub fn with_api_config(
api: OpenH264API,
config: EncoderConfig,
) -> Result<Self, Error>
pub fn with_api_config( api: OpenH264API, config: EncoderConfig, ) -> Result<Self, Error>
Create an encoder with the provided API and configuration.
The width and height will be taken from the YUVSource when calling Encoder::encode().
§Errors
Might fail if the provided encoder parameters had issues.
Sourcepub fn encode<T: YUVSource>(
&mut self,
yuv_source: &T,
) -> Result<EncodedBitStream<'_>, Error>
pub fn encode<T: YUVSource>( &mut self, yuv_source: &T, ) -> Result<EncodedBitStream<'_>, Error>
Encodes a YUV source and returns the encoded bitstream.
The returned bitstream consists of one or more NAL units or packets. The first packets contain initialization information. Subsequent packages then contain, amongst others, keyframes (“I frames”) or delta frames. The interval at which they are produced depends on the encoder settings.
The resolution of the encoded frame is allowed to change. Each time it changes, the encoder is re-initialized with the new values.
§Errors
This might error for various reasons, many of which aren’t clearly documented in OpenH264.
Sourcepub fn encode_at<T: YUVSource>(
&mut self,
yuv_source: &T,
timestamp: Timestamp,
) -> Result<EncodedBitStream<'_>, Error>
pub fn encode_at<T: YUVSource>( &mut self, yuv_source: &T, timestamp: Timestamp, ) -> Result<EncodedBitStream<'_>, Error>
Encodes a YUV source and returns the encoded bitstream.
The returned bitstream consists of one or more NAL units or packets. The first packets contain initialization information. Subsequent packages then contain, amongst others, keyframes (“I frames”) or delta frames. The interval at which they are produced depends on the encoder settings.
The resolution of the encoded frame is allowed to change. Each time it changes, the encoder is re-initialized with the new values.
§Panics
Panics if the provided timestamp as milliseconds is out of range of i64.
§Errors
This might error for various reasons, many of which aren’t clearly documented in OpenH264.
Sourcepub fn force_intra_frame(&mut self)
pub fn force_intra_frame(&mut self)
Forces the encoder to emit an intra frame (I-frame, “keyframe”) for the next encoded frame.
Sourcepub const unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI
pub const unsafe fn raw_api(&mut self) -> &mut EncoderRawAPI
Obtain the raw API for advanced use cases.
When resorting to this call, please consider filing an issue / PR.
§Safety
You must not set parameters the encoder relies on, we recommend checking the source.