pub struct Capture {
pub(crate) video_encoder: Arc<Mutex<dyn VideoEncoder + Send>>,
pub(crate) audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>,
pub(crate) stop_flag: Arc<AtomicBool>,
pub(crate) pause_flag: Arc<AtomicBool>,
pub(crate) egl_ctx: Arc<EglContext>,
pub(crate) worker_handles: Vec<JoinHandle<()>>,
pub(crate) pw_video_terminate_tx: Sender<Terminate>,
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::{CaptureBuilder, QualityPreset, VideoEncoder};
// Create a capture instance
let mut capture = CaptureBuilder::new()
.with_quality_preset(QualityPreset::Medium)
.with_video_encoder(VideoEncoder::Vaapi)
.build()
.expect("Failed to create capture");
// Start the capture
capture.start().expect("Failed to start capture");
// Get video receiver
let video_receiver = capture.take_video_receiver();
// Process Frames
while let Some(encoded_frame) = video_receiver.try_pop() {
println!("Received an encoded frame");
}
Fields§
§video_encoder: Arc<Mutex<dyn VideoEncoder + Send>>
§audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>
§stop_flag: Arc<AtomicBool>
§pause_flag: Arc<AtomicBool>
§egl_ctx: Arc<EglContext>
§worker_handles: Vec<JoinHandle<()>>
§pw_video_terminate_tx: Sender<Terminate>
§pw_audio_terminate_tx: Option<Sender<Terminate>>
Implementations§
Source§impl Capture
impl Capture
pub(crate) fn new( video_encoder_type: VideoEncoderType, audio_encoder_type: AudioEncoderType, quality: QualityPreset, include_cursor: bool, include_audio: bool, target_fps: u64, ) -> Result<Self>
Sourcepub fn start(&mut self) -> Result<()>
pub fn start(&mut self) -> Result<()>
Enables capture streams to send their frames to their encoders
Sourcepub fn pause(&mut self) -> Result<()>
pub fn pause(&mut self) -> Result<()>
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
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 CaptureBuilder
to record again.
If your goal is to temporarily stop recording use Self::pause
or Self::finish
+ Self::reset
Sourcepub fn take_video_receiver(&mut self) -> HeapCons<EncodedVideoFrame>
pub fn take_video_receiver(&mut self) -> HeapCons<EncodedVideoFrame>
Take ownership of the ring buffer which will supply you with encoded video frame data
IMPORTANT
This gives you ownership of the buffer so this can only be called once
Sourcepub fn take_audio_receiver(&mut self) -> Result<HeapCons<EncodedAudioFrame>>
pub fn take_audio_receiver(&mut self) -> Result<HeapCons<EncodedAudioFrame>>
Take ownership of the ring buffer which will supply you with encoded audio frame data
IMPORTANT
This gives you ownership of the buffer so this can only be called once
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::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::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()?;