Skip to main content

AudioEncoder

Struct AudioEncoder 

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

Audio encoder.

Encodes audio frames to a file using FFmpeg.

§Examples

use ff_encode::{AudioEncoder, AudioCodec};
use ff_format::{AudioFrame, SampleFormat};

let mut encoder = AudioEncoder::create("output.m4a")
    .expect("Failed to create encoder")
    .audio(48000, 2)
    .audio_codec(AudioCodec::Aac)
    .build_audio()
    .expect("Failed to build encoder");

// Create and push audio frames
let frame = AudioFrame::empty(1024, 2, 48000, SampleFormat::F32).unwrap();
encoder.push(&frame).expect("Failed to push frame");

encoder.finish().expect("Failed to finish encoding");

Implementations§

Source§

impl AudioEncoder

Source

pub fn create<P: AsRef<Path>>(path: P) -> Result<EncoderBuilder, EncodeError>

Create a new encoder builder with the given output path.

§Arguments
  • path - Output file path
§Returns

Returns an EncoderBuilder for configuring the encoder.

§Examples
use ff_encode::AudioEncoder;

let builder = AudioEncoder::create("output.m4a")?;
Source

pub fn actual_codec(&self) -> &str

Get the actual audio codec being used.

Returns the name of the FFmpeg encoder (e.g., “aac”, “libopus”).

Source

pub fn push(&mut self, frame: &AudioFrame) -> Result<(), EncodeError>

Push an audio frame for encoding.

§Arguments
  • frame - The audio frame to encode
§Errors

Returns an error if encoding fails or the encoder is not initialized.

§Examples
use ff_encode::{AudioEncoder, AudioCodec};
use ff_format::{AudioFrame, SampleFormat};

let mut encoder = AudioEncoder::create("output.m4a")?
    .audio(48000, 2)
    .audio_codec(AudioCodec::Aac)
    .build()?;

let frame = AudioFrame::empty(1024, 2, 48000, SampleFormat::F32)?;
encoder.push(&frame)?;
Source

pub fn finish(self) -> Result<(), EncodeError>

Finish encoding and write the file trailer.

This method must be called to properly finalize the output file. It flushes any remaining encoded frames and writes the file trailer.

§Errors

Returns an error if finalizing fails.

Trait Implementations§

Source§

impl Drop for AudioEncoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.