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
impl CompressedEncoder
Sourcepub fn new(width: u32, height: u32, qp: i32) -> Self
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).
Sourcepub fn deblock(self, on: bool) -> Self
pub fn deblock(self, on: bool) -> Self
Turn the in-loop deblocking filter on or off. On by default.
Sourcepub fn entropy(self, mode: EntropyMode) -> Self
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.
Sourcepub fn aq(self, strength: f32) -> Self
pub fn aq(self, strength: f32) -> Self
Set the adaptive-quantization strength (see
H264Config::aq_strength). Off by default.
Sourcepub fn config(&self) -> &H264Config
pub fn config(&self) -> &H264Config
The configuration the parameter sets describe.
Sourcepub fn sps(&self) -> &[u8] ⓘ
pub fn sps(&self) -> &[u8] ⓘ
The sequence parameter set NAL unit: header included, no start code.
Sourcepub fn pps(&self) -> &[u8] ⓘ
pub fn pps(&self) -> &[u8] ⓘ
The picture parameter set NAL unit: header included, no start code.
Sourcepub fn encode_frame(&mut self, frame: &Yuv420Frame) -> (Vec<u8>, Reconstruction)
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.
Sourcepub fn encode_slice_au(&self, frame: &Yuv420Frame) -> Vec<u8> ⓘ
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.
Sourcepub fn encode_slice_au_at(&self, frame: &Yuv420Frame, qp: i32) -> Vec<u8> ⓘ
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.
Sourcepub fn avcc(&self) -> Vec<u8> ⓘ
pub fn avcc(&self) -> Vec<u8> ⓘ
The avcC decoder configuration for this stream, as an MP4 muxer
(mp4_stream::VideoConfig::avcc) wants it.
Sourcepub fn encode_sample(&self, frame: &Yuv420Frame) -> Vec<u8> ⓘ
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.
Sourcepub fn encode_sample_at(&self, frame: &Yuv420Frame, qp: i32) -> Vec<u8> ⓘ
pub fn encode_sample_at(&self, frame: &Yuv420Frame, qp: i32) -> Vec<u8> ⓘ
encode_sample at a quantizer chosen per frame.
Auto Trait Implementations§
impl Forget for CompressedEncoder
impl Freeze for CompressedEncoder
impl Move for CompressedEncoder
impl RefUnwindSafe for CompressedEncoder
impl Send for CompressedEncoder
impl Sync for CompressedEncoder
impl Unpin for CompressedEncoder
impl UnsafeUnpin for CompressedEncoder
impl UnwindSafe for CompressedEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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