Skip to main content

AudioEncoder

Trait AudioEncoder 

Source
pub trait AudioEncoder {
    // Required methods
    fn config(&self) -> &EncoderConfig;
    fn format(&self) -> AudioEncoderFormat;
    fn encode<'a>(
        &'a mut self,
        index: FrameIndex,
        buffer: AudioBuffer,
    ) -> EncoderFuture<'a, Vec<EncodedSample>>;
    fn finish<'a>(&'a mut self) -> EncoderFuture<'a, AudioDrain>;
}
Expand description

Backend-neutral audio encoder contract.

§Where the audio encoders come from

  • AAC-LC: native_aac_audio_encoder_factory uses the operating system’s encoder, AudioToolbox on macOS and Media Foundation on Windows, and zvidlib’s own pure-Rust AAC-LC encoder everywhere else; aac_audio_encoder_factory(HardwarePreference::Avoid) picks the pure-Rust encoder on every target. No open reference AAC encoder has a license this crate can carry, so the pure-Rust encoder is an original design (issue #704), held to sample-exact gapless round trips and a quality bound through FFmpeg and the platform decoders. The browser build encodes through WebCodecs.
  • Opus: native_opus_audio_encoder_factory runs opus-pure, a pure-Rust port of libopus, on every target; the browser build can also encode through WebCodecs.
  • Vorbis: native_vorbis_audio_encoder_factory runs zvidlib’s own port of the libvorbis 1.3.7 encoder, whose packets are bit-identical to libvorbis’s for the same input and quality.

crate::MediaOutput muxes an audio track given any AudioEncoder, so a caller with an encoder of its own still plugs it in here.

Required Methods§

Source

fn config(&self) -> &EncoderConfig

Source

fn format(&self) -> AudioEncoderFormat

Source

fn encode<'a>( &'a mut self, index: FrameIndex, buffer: AudioBuffer, ) -> EncoderFuture<'a, Vec<EncodedSample>>

Source

fn finish<'a>(&'a mut self) -> EncoderFuture<'a, AudioDrain>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§