Skip to main content

CompressedEncoder

Struct CompressedEncoder 

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

A compressed intra H.264 encoder: pixels in, Annex-B out.

Every frame is an IDR whose macroblocks are I_NxN or I_16x16, whichever costs less. This is the counterpart to super::encoder::H264Encoder, which codes I_PCM and so does not compress at all.

Implementations§

Source§

impl CompressedEncoder

Source

pub fn new(width: u32, height: u32, qp: i32) -> Self

New encoder for width × height at quantization qp (roughly 18–40 useful, lower is bigger and better).

Source

pub fn deblock(self, on: bool) -> Self

Turn the in-loop deblocking filter on or off. On by default.

Source

pub fn entropy(self, mode: EntropyMode) -> Self

Choose the entropy coder. CABAC by default; CAVLC produces a Baseline-profile stream, which is larger but reaches older hardware.

Source

pub fn aq(self, strength: f32) -> Self

Set the adaptive-quantization strength (see H264Config::aq_strength). Off by default.

Source

pub fn config(&self) -> &H264Config

The configuration the parameter sets describe.

Source

pub fn sps(&self) -> &[u8] ⓘ

The sequence parameter set NAL unit: header included, no start code.

Source

pub fn pps(&self) -> &[u8] ⓘ

The picture parameter set NAL unit: header included, no start code.

Source

pub fn encode_frame(&mut self, frame: &Yuv420Frame) -> (Vec<u8>, Reconstruction)

Encode one 4:2:0 frame → Annex-B access unit, plus the reconstruction a conformant decoder must reproduce. The first call prepends SPS/PPS.

Source

pub fn encode_slice_au(&self, frame: &Yuv420Frame) -> Vec<u8> ⓘ

One frame’s slice NAL, in Annex-B form, without SPS or PPS.

Takes &self. An all-intra stream carries nothing between frames — compressed_slice_rbsp reads the config and the pixels and nothing else — so frames can be encoded on separate threads and the result is byte-identical to encoding them in order.

Source

pub fn encode_slice_au_at(&self, frame: &Yuv420Frame, qp: i32) -> Vec<u8> ⓘ

encode_slice_au at a quantizer chosen per frame, which is what rate control needs.

Only the slice header moves: pic_init_qp_minus26 stays zero in the PPS and the frame’s quantizer rides in slice_qp_delta, so one SPS and PPS serve every frame however the rate controller steers.

Source

pub fn avcc(&self) -> Vec<u8> ⓘ

The avcC decoder configuration for this stream, as an MP4 muxer (mp4_stream::VideoConfig::avcc) wants it.

Source

pub fn encode_sample(&self, frame: &Yuv420Frame) -> Vec<u8> ⓘ

One frame as an MP4 sample: the slice NAL, 4-byte length-prefixed, ready for Mp4StreamWriter::write_video_sample (parameter sets go in avcc, not here). Takes &self, like encode_slice_au, so frames can be encoded in parallel.

Source

pub fn encode_sample_at(&self, frame: &Yuv420Frame, qp: i32) -> Vec<u8> ⓘ

encode_sample at a quantizer chosen per frame.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.