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>
impl<V: VideoEncoder + PipewireSPA + StartVideoEncoder> Capture<V>
pub fn new_with_encoder(
video_encoder: V,
include_cursor: bool,
target_fps: u64,
) -> Result<Self>where
V: 'static,
pub(crate) fn start_pipewire_video( &mut self, include_cursor: bool, ) -> Result<(Receiver<RawVideoFrame>, Arc<ReadyState>, Resolution)>
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>
impl<V: VideoEncoder> Capture<V>
Sourcepub fn start(&mut self) -> Result<()>
pub fn start(&mut self) -> Result<()>
Enables capture streams to send their frames to their encoders
Sourcepub fn controls(&mut self) -> Arc<CaptureControls>
pub fn controls(&mut self) -> Arc<CaptureControls>
Temporarily stops the recording by blocking frames from being sent to the encoders
Sourcepub fn finish(&mut self) -> Result<()>
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.
Sourcepub fn reset(&mut self) -> Result<()>
pub fn reset(&mut self) -> Result<()>
Resets the encoder states so we can resume encoding from within this same session
Sourcepub fn close(&mut self) -> Result<()>
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
pub fn get_output(&mut self) -> Receiver<V::Output>
Source§impl Capture<DynamicEncoder>
impl Capture<DynamicEncoder>
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>
Sourcepub fn get_video_receiver(&mut self) -> Receiver<EncodedVideoFrame>
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.
Sourcepub fn get_audio_receiver(&mut self) -> Result<Receiver<EncodedAudioFrame>>
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.
Sourcepub fn with_video_encoder<F, R>(&self, f: F) -> R
pub fn with_video_encoder<F, R>(&self, f: F) -> 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()?;
Sourcepub fn with_audio_encoder<F, R>(&self, f: F) -> R
pub fn with_audio_encoder<F, R>(&self, f: F) -> 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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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