Skip to main content

Encoder

Struct Encoder 

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

Video encoder.

This encoder uses semi-standard pipeline with the simplest and fastest implementation for each stage. Currently the following stages are implemented.

StageHow it is implemented
RGB to YUV conversionPGF (no division).
TransformHaar transform (no division).
QuantizationScalar quantization without a deadzone.
Motion estimationSimple delta encoding.
Bit encoderSign-magniude conversion and rANS encoder.

§Example

use core::num::NonZero;
use corevm_codec::video;

let rgb_frame = [
    0,   0, 0,
    100, 0, 0,
    0, 100, 0,
    0, 0, 100,
];
let width = NonZero::new(2).unwrap();
let height = width;
let mut output = Vec::new();
let config = video::Config::default();
let mut encoder = video::Encoder::new(width, height, config);
encoder.start(&mut output);
encoder.write_rgb888_frame(&rgb_frame, &mut output);
encoder.finish(&mut output);

Implementations§

Source§

impl Encoder

Source

pub fn new(width: NonZero<u16>, height: NonZero<u16>, config: Config) -> Self

Creates new encoder with the provided width, height, and configuration.

Source

pub fn write_rgb888_frame( &mut self, rgb_frame: &[u8], output: &mut impl Output, ) -> Stats

Encode RGB888 frame and append the resulting bytes to the output.

Source

pub fn write_rgb888_indexed8_frame( &mut self, indexed_rgb_frame: &[u8], output: &mut impl Output, ) -> Stats

Encode indexed RGB888 frame and append the resulting bytes to the output.

The frame consists of a 256-color palette and an array of 8-bit indices into the palette. Each palette element is encoded as RGB888.

Source

pub fn start(&mut self, output: &mut impl Output)

Write stream header.

Source

pub fn finish(self, _output: &mut impl Output)

Write stream footer.

This is currently empty but might change in the future.

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.