Skip to main content

Encoder

Struct Encoder 

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

An OpenH264 encoder.

Implementations§

Source§

impl Encoder

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn force_intra_frame(&mut self)

Forces the encoder to emit an intra frame (I-frame, “keyframe”) for the next encoded frame.

Source

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.

Trait Implementations§

Source§

impl Drop for Encoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Encoder

Source§

impl Sync for Encoder

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.