pub struct AudioDecoderBuilder { /* private fields */ }Expand description
Builder for configuring and constructing an AudioDecoder.
This struct provides a fluent interface for setting up decoder options
before opening an audio file. It is created by calling AudioDecoder::open().
§Examples
§Basic Usage
use ff_decode::AudioDecoder;
let decoder = AudioDecoder::open("audio.mp3")?
.build()?;§With Custom Format and Sample Rate
use ff_decode::AudioDecoder;
use ff_format::SampleFormat;
let decoder = AudioDecoder::open("audio.mp3")?
.output_format(SampleFormat::F32)
.output_sample_rate(48000)
.build()?;Implementations§
Source§impl AudioDecoderBuilder
impl AudioDecoderBuilder
Sourcepub fn output_format(self, format: SampleFormat) -> Self
pub fn output_format(self, format: SampleFormat) -> Self
Sets the output sample format for decoded frames.
If not set, frames are returned in the source format. Setting an output format enables automatic conversion during decoding.
§Common Formats
SampleFormat::F32- 32-bit float, most common for editingSampleFormat::I16- 16-bit integer, CD qualitySampleFormat::F32p- Planar 32-bit float, efficient for processing
§Examples
use ff_decode::AudioDecoder;
use ff_format::SampleFormat;
let decoder = AudioDecoder::open("audio.mp3")?
.output_format(SampleFormat::F32)
.build()?;Sourcepub fn output_sample_rate(self, sample_rate: u32) -> Self
pub fn output_sample_rate(self, sample_rate: u32) -> Self
Sets the output sample rate in Hz.
If not set, frames are returned at the source sample rate. Setting an output sample rate enables automatic resampling during decoding.
§Common Sample Rates
- 44100 Hz - CD quality audio
- 48000 Hz - Professional audio, most common in video
- 96000 Hz - High-resolution audio
§Examples
use ff_decode::AudioDecoder;
// Resample to 48kHz
let decoder = AudioDecoder::open("audio.mp3")?
.output_sample_rate(48000)
.build()?;Sourcepub fn output_channels(self, channels: u32) -> Self
pub fn output_channels(self, channels: u32) -> Self
Sets the output channel count.
If not set, frames are returned with the source channel count. Setting an output channel count enables automatic channel remixing during decoding.
§Common Channel Counts
- 1 - Mono
- 2 - Stereo
- 6 - 5.1 surround sound
§Examples
use ff_decode::AudioDecoder;
// Convert to stereo
let decoder = AudioDecoder::open("audio.mp3")?
.output_channels(2)
.build()?;Sourcepub fn get_output_format(&self) -> Option<SampleFormat>
pub fn get_output_format(&self) -> Option<SampleFormat>
Returns the configured output format, if any.
Sourcepub fn get_output_sample_rate(&self) -> Option<u32>
pub fn get_output_sample_rate(&self) -> Option<u32>
Returns the configured output sample rate, if any.
Sourcepub fn get_output_channels(&self) -> Option<u32>
pub fn get_output_channels(&self) -> Option<u32>
Returns the configured output channel count, if any.
Sourcepub fn build(self) -> Result<AudioDecoder, DecodeError>
pub fn build(self) -> Result<AudioDecoder, DecodeError>
Builds the audio decoder with the configured options.
This method opens the media file, initializes the decoder context, and prepares for frame decoding.
§Errors
Returns an error if:
- The file cannot be found (
DecodeError::FileNotFound) - The file contains no audio stream (
DecodeError::NoAudioStream) - The codec is not supported (
DecodeError::UnsupportedCodec) - Other
FFmpegerrors occur (DecodeError::Ffmpeg)
§Examples
use ff_decode::AudioDecoder;
let decoder = AudioDecoder::open("audio.mp3")?
.build()?;
// Start decoding
for frame in decoder.frames().take(100) {
let frame = frame?;
// Process frame...
}