Skip to main content

AudioAdder

Struct AudioAdder 

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

Mux an audio track into a silent (or existing) video file.

The video bitstream is stream-copied (no decode/encode cycle). When the audio source is shorter than the video and loop_audio has been called, the audio is looped by re-seeking and advancing the PTS offset until the video is exhausted.

Returns EncodeError::MediaOperationFailed when no video stream is found in video_input or no audio stream is found in audio_input.

§Example

use ff_encode::AudioAdder;

AudioAdder::new("silent.mp4", "soundtrack.mp3", "output.mp4")
    .loop_audio()
    .run()?;

Implementations§

Source§

impl AudioAdder

Source

pub fn new( video_input: impl Into<PathBuf>, audio_input: impl Into<PathBuf>, output: impl Into<PathBuf>, ) -> Self

Create a new AudioAdder.

  • video_input — source file whose video stream is kept.
  • audio_input — source file whose first audio stream is used.
  • output — path for the combined output file.
Source

pub fn loop_audio(self) -> Self

Loop the audio when it is shorter than the video.

The audio is re-seeked to the start and the PTS offset is advanced each time the audio stream is exhausted, until the video ends.

Source

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

Execute the audio addition operation.

§Errors

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.