Struct Context
struct Context<T: Pixel> { ... }
The encoder context.
Contains the encoding state.
Implementations
impl<T: Pixel> Context<T>
fn rc_summary_size(self: &Self) -> usizeReturn the Rate Control Summary Packet size
It is useful mainly to preserve space when saving both Rate Control Summary and Frame Packets in a single file.
fn rc_receive_pass_data(self: &mut Self) -> Option<RcData>Return the first pass data
Call it after
receive_packet, it returns a packet or the encoder lifecycle statusesEncoderStatus::EncodedandEncoderStatus::LimitReached.It will return a
RcData::Summaryonce the encoder is flushed.fn rc_second_pass_data_required(self: &Self) -> usizeLower bound number of pass data packets required to progress the encoding process.
It should be called iteratively until it returns 0.
fn rc_send_pass_data(self: &mut Self, data: &[u8]) -> Result<(), EncoderStatus>Feed the first pass Rate Control data to the encoder, Frame-specific Packets only.
Call it before
receive_packet()Errors
Returns
EncoderStatus::Failureif the data provided is incorrect
impl<T: Pixel> Context<T>
fn new_frame(self: &Self) -> Frame<T>Allocates and returns a new frame.
Examples
use *; #fn send_frame<F>(self: &mut Self, frame: F) -> Result<(), EncoderStatus> where F: IntoFrame<T>Sends the frame for encoding.
This method adds the frame into the frame queue and runs the first passes of the look-ahead computation.
Passing
Noneis equivalent to callingflush.The caller is responsible for padding the invisible portion of the frame, if multiple references to the frame are held. Calling [
Plane::pad()] after filling each plane or equivalent is required.Errors
If this method is called with a frame after the encoder has been flushed or the encoder internal limit is hit (
std::i32::MAXframes) theEncoderStatus::EnoughDataerror is returned.Examples
use *; #fn twopass_out(self: &mut Self) -> Option<&[u8]>Returns the first-pass data of a two-pass encode for the frame that was just encoded.
This should be called BEFORE every call to
receive_packet(including the very first one), even if no packet was produced by the last call toreceive_packet, if any (i.e.,EncoderStatus::Encodedwas returned). It needs to be called once more afterEncoderStatus::LimitReachedis returned, to retrieve the header that should be written to the front of the stats file (overwriting the placeholder header that was emitted at the start of encoding).It is still safe to call this function when
receive_packetreturns any other error. It will returnNoneinstead of returning a duplicate copy of the previous frame's data.fn twopass_bytes_needed(self: &mut Self) -> usizeReturns the number of bytes of the stats file needed before the next frame of the second pass in a two-pass encode can be encoded.
This is a lower bound (more might be required), but if
0is returned, then encoding can proceed. This is just a hint to the application, and does not need to be called for encoding the second pass to work, so long as the application continues to provide more data totwopass_inin a loop untiltwopass_inreturns0.fn twopass_in(self: &mut Self, buf: &[u8]) -> Result<usize, EncoderStatus>Provides the stats data produced in the first pass of a two-pass encode to the second pass.
On success this returns the number of bytes of the data which were consumed. When encoding the second pass of a two-pass encode, this should be called repeatedly in a loop before every call to
receive_packet(including the very first one) until no bytes are consumed, or untiltwopass_bytes_neededreturns0.Errors
Returns
Err(EncoderStatus::Failure)if the two-pass data is invalid.fn receive_packet(self: &mut Self) -> Result<Packet<T>, EncoderStatus>Encodes the next frame and returns the encoded data.
This method is where the main encoding work is done.
Errors
May return
Err(EncoderStatus), which should be handled by the caller.Examples
Encoding a single frame:
use *; #Encoding a sequence of frames:
use Arc; use *; #fn flush(self: &mut Self)Flushes the encoder.
Flushing signals the end of the video. After the encoder has been flushed, no additional frames are accepted.
Panics
Panics if
send_framereturns anErr. This should never happen when calling it withNoneand indicates a development error.fn container_sequence_header(self: &Self) -> Vec<u8>Produces a sequence header matching the current encoding context.
Its format is compatible with the AV1 Matroska and ISOBMFF specification. Note that the returned header does not include any config OBUs which are required for some uses. See the specification.
Panics
Panics if the header cannot be written in memory. This is unrecoverable, and usually indicates the system is out of memory.
impl<T> Any for Context<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Context<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Context<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Freeze for Context<T>
impl<T> From for Context<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Context<T>
impl<T> Send for Context<T>
impl<T> Sync for Context<T>
impl<T> Unpin for Context<T>
impl<T> UnsafeUnpin for Context<T>
impl<T> UnwindSafe for Context<T>
impl<T, U> Into for Context<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Context<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Context<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: Pixel> Debug for Context<T>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result<(), Error>