Struct Capture

Source
pub struct Capture<V: VideoEncoder + Send> {
    pub(crate) controls: Arc<CaptureControls>,
    pub(crate) worker_handles: Vec<JoinHandle<Result<()>>>,
    pub(crate) video_encoder: Option<Arc<Mutex<V>>>,
    pub(crate) pw_video_terminate_tx: Option<Sender<Terminate>>,
    pub(crate) audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>,
    pub(crate) pw_audio_terminate_tx: Option<Sender<Terminate>>,
}
Expand description

Main capture instance for recording screen content and audio.

Capture provides methods to control the recording process, retrieve encoded frames, and manage the capture lifecycle.

§Examples

use waycap_rs::pipeline::builder::CaptureBuilder;
use waycap_rs::types::config::{QualityPreset, VideoEncoder};

// Create a capture instance
let mut capture = CaptureBuilder::new()
    .with_quality_preset(QualityPreset::Medium)
    .with_video_encoder(VideoEncoder::H264Vaapi)
    .build()
    .expect("Failed to create capture");

// Start the capture
capture.start().expect("Failed to start capture");

// Get video receiver
let video_receiver = capture.get_video_receiver();

// Process Frames
loop {
    let frame = video_receiver.recv();
    println!("Received an encoded frame");
}

Fields§

§controls: Arc<CaptureControls>§worker_handles: Vec<JoinHandle<Result<()>>>§video_encoder: Option<Arc<Mutex<V>>>§pw_video_terminate_tx: Option<Sender<Terminate>>§audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>§pw_audio_terminate_tx: Option<Sender<Terminate>>

Implementations§

Source§

impl<V: VideoEncoder + PipewireSPA + StartVideoEncoder> Capture<V>

Source

pub fn new_with_encoder( video_encoder: V, include_cursor: bool, target_fps: u64, ) -> Result<Self>
where V: 'static,

Source

pub(crate) fn start_pipewire_video( &mut self, include_cursor: bool, ) -> Result<(Receiver<RawVideoFrame>, Arc<ReadyState>, Resolution)>

Source

pub(crate) fn start_pipewire_audio( &mut self, audio_encoder_type: AudioEncoderType, ready_state: Arc<ReadyState>, ) -> Result<Receiver<RawAudioFrame>>

Source§

impl<V: VideoEncoder> Capture<V>

Source

pub fn start(&mut self) -> Result<()>

Enables capture streams to send their frames to their encoders

Source

pub fn controls(&mut self) -> Arc<CaptureControls>

Temporarily stops the recording by blocking frames from being sent to the encoders

Source

pub fn finish(&mut self) -> Result<()>

Stop recording and drain the encoders of any last frames they have in their internal buffers. These frames are discarded.

Source

pub fn reset(&mut self) -> Result<()>

Resets the encoder states so we can resume encoding from within this same session

Source

pub fn close(&mut self) -> Result<()>

Close the connection. Once called the struct cannot be re-used and must be re-built with the crate::pipeline::builder::CaptureBuilder to record again. If your goal is to temporarily stop recording use [Self::pause] or Self::finish + Self::reset

Source

pub fn get_output(&mut self) -> Receiver<V::Output>

Source§

impl Capture<DynamicEncoder>

Source

pub fn new( video_encoder_type: Option<VideoEncoderType>, audio_encoder_type: AudioEncoderType, quality: QualityPreset, include_cursor: bool, include_audio: bool, target_fps: u64, ) -> Result<Self>

Source

pub fn get_video_receiver(&mut self) -> Receiver<EncodedVideoFrame>

Get a channel for which to receive encoded video frames.

Returns a [crossbeam::channel::Receiver] which allows multiple consumers. Each call creates a new consumer that will receive all future frames.

Source

pub fn get_audio_receiver(&mut self) -> Result<Receiver<EncodedAudioFrame>>

Get a channel for which to receive encoded audio frames.

Returns a [crossbeam::channel::Receiver] which allows multiple consumers. Each call creates a new consumer that will receive all future frames.

Source

pub fn with_video_encoder<F, R>(&self, f: F) -> R
where F: FnOnce(&Option<Video>) -> R,

Perform an action with the video encoder

§Examples
let mut output = ffmpeg_next::format::output(&filename)?;

capture.with_video_encoder(|enc| {
    if let Some(video_encoder) = enc {
        let mut video_stream = output.add_stream(video_encoder.codec().unwrap()).unwrap();
        video_stream.set_time_base(video_encoder.time_base());
        video_stream.set_parameters(video_encoder);
    }
});
output.write_header()?;
Source

pub fn with_audio_encoder<F, R>(&self, f: F) -> R
where F: FnOnce(&Option<Audio>) -> R,

Perform an action with the audio encoder

§Examples
let mut output = ffmpeg_next::format::output(&filename)?;
capture.with_audio_encoder(|enc| {
    if let Some(audio_encoder) = enc {
        let mut audio_stream = output.add_stream(audio_encoder.codec().unwrap()).unwrap();
        audio_stream.set_time_base(audio_encoder.time_base());
        audio_stream.set_parameters(audio_encoder);

    }
});
output.write_header()?;

Trait Implementations§

Source§

impl<V: VideoEncoder> Drop for Capture<V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<V> Freeze for Capture<V>

§

impl<V> !RefUnwindSafe for Capture<V>

§

impl<V> Send for Capture<V>

§

impl<V> Sync for Capture<V>

§

impl<V> Unpin for Capture<V>

§

impl<V> !UnwindSafe for Capture<V>

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V