Skip to main content

EncodeProgressCallback

Trait EncodeProgressCallback 

Source
pub trait EncodeProgressCallback: Send {
    // Required method
    fn on_progress(&mut self, progress: &EncodeProgress);

    // Provided method
    fn should_cancel(&self) -> bool { ... }
}
Expand description

EncodeProgress callback trait for monitoring encoding progress.

Implement this trait to receive real-time encoding progress updates and optionally support encoding cancellation.

§Examples

use ff_encode::{EncodeProgress, EncodeProgressCallback};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

struct MyEncodeProgressHandler {
    cancelled: Arc<AtomicBool>,
}

impl EncodeProgressCallback for MyEncodeProgressHandler {
    fn on_progress(&mut self, progress: &EncodeProgress) {
        println!("Encoded {} frames at {:.1} fps",
            progress.frames_encoded,
            progress.current_fps
        );
    }

    fn should_cancel(&self) -> bool {
        self.cancelled.load(Ordering::Relaxed)
    }
}

Required Methods§

Source

fn on_progress(&mut self, progress: &EncodeProgress)

Called when encoding progress is updated.

This method is called periodically during encoding to report progress. The frequency of calls depends on the encoding speed and frame rate.

§Arguments
  • progress - Current encoding progress information

Provided Methods§

Source

fn should_cancel(&self) -> bool

Check if encoding should be cancelled.

The encoder will check this method periodically during encoding. Return true to request cancellation of the encoding process.

§Returns

true to cancel encoding, false to continue

§Default Implementation

The default implementation returns false (never cancel).

Implementors§

Source§

impl<F> EncodeProgressCallback for F
where F: FnMut(&EncodeProgress) + Send,

Implement EncodeProgressCallback for closures.

This allows using simple closures as progress callbacks without needing to define a custom struct implementing the trait.