Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

clippy

Richie McIlroy4b70ba83a90f
diff --git a/crates/camera-directshow/examples/cli.rs b/crates/camera-directshow/examples/cli.rs
index d712c1a65..f154aa99a 100644
--- a/crates/camera-directshow/examples/cli.rs
+++ b/crates/camera-directshow/examples/cli.rs
@@ -114,10 +114,11 @@ mod windows {
.start_capturing(
&selected_format.media_type,
Box::new(|frame| {
- unsafe { dbg!(frame.sample.GetActualDataLength()) };
- // dbg!(frame.media_type.subtype_str());
- // dbg!(frame.reference_time);
- dbg!(frame.timestamp);
+ let data_length = unsafe { frame.sample.GetActualDataLength() };
+ println!(
+ "Frame: data_length={data_length:?}, timestamp={:?}",
+ frame.timestamp
+ );
}),
)
.unwrap();
diff --git a/crates/camera-mediafoundation/examples/cli.rs b/crates/camera-mediafoundation/examples/cli.rs
index 317e15f65..86e4881e3 100644
--- a/crates/camera-mediafoundation/examples/cli.rs
+++ b/crates/camera-mediafoundation/examples/cli.rs
@@ -21,7 +21,7 @@ mod windows {
let device_sources = DeviceSourcesIterator::new().unwrap();
- if device_sources.len() == 0 {
+ if device_sources.is_empty() {
warn!("No devices found");
return;
}
diff --git a/crates/camera-windows/examples/cli.rs b/crates/camera-windows/examples/cli.rs
index 76b241bb7..fbf898bc0 100644
--- a/crates/camera-windows/examples/cli.rs
+++ b/crates/camera-windows/examples/cli.rs
@@ -32,7 +32,8 @@ mod windows {
let Ok(bytes) = frame.bytes() else {
return;
};
- dbg!(
+ println!(
+ "Frame: len={}, pixel_format={:?}, timestamp={:?}, perf_counter={:?}",
bytes.len(),
frame.pixel_format,
frame.timestamp,
diff --git a/crates/enc-mediafoundation/examples/cli.rs b/crates/enc-mediafoundation/examples/cli.rs
index 72f20574e..f24f0a4fa 100644
--- a/crates/enc-mediafoundation/examples/cli.rs
+++ b/crates/enc-mediafoundation/examples/cli.rs
@@ -143,8 +143,7 @@ mod win {
.run(
should_stop_encoder,
|| Ok(frame_rx.recv().ok().flatten()),
- |sample| {
- dbg!(sample);
+ |_sample| {
Ok(())
// sample_writer.write(stream_index, &output_sample).unwrap()
},
diff --git a/crates/mediafoundation-ffmpeg/examples/usage.rs b/crates/mediafoundation-ffmpeg/examples/usage.rs
index f37ad8157..f000fe7de 100644
--- a/crates/mediafoundation-ffmpeg/examples/usage.rs
+++ b/crates/mediafoundation-ffmpeg/examples/usage.rs
@@ -9,63 +9,6 @@ mod win {
use ffmpeg::format;
use std::path::PathBuf;
- /// Example of using H264StreamMuxer with an existing FFmpeg output context
- /// This demonstrates how to integrate with MP4File or similar structures
- fn example_with_shared_output() -> Result<(), Box<dyn std::error::Error>> {
- // Initialize FFmpeg
- ffmpeg::init()?;
-
- // Create an output context (this would normally be owned by MP4File)
- let output_path = PathBuf::from("output.mp4");
- let mut output = format::output(&output_path)?;
-
- // Configure the H264 muxer
- let config = MuxerConfig {
- width: 1920,
- height: 1080,
- fps: 30,
- bitrate: 5_000_000, // 5 Mbps
- };
-
- // Add the H264 stream and create the muxer
- // Note: We need to add the stream before writing the header
- let mut h264_muxer = H264StreamMuxer::new(&mut output, config)?;
-
- // You might also have other streams (like audio) added to the same output
- // ... add audio stream here if needed ...
-
- // Write the header after all streams are added
- output.write_header()?;
-
- // Now you can write H264 samples from MediaFoundation
- #[cfg(windows)]
- {
- // Example: Write samples from MediaFoundation
- // let sample: IMFSample = get_sample_from_media_foundation();
- // h264_muxer.write_sample(&sample)?;
- }
-
- // Or write raw H264 data
- let example_h264_data = vec![0, 0, 0, 1, 0x65]; // Example keyframe NAL
- h264_muxer.write_h264_data(
- &example_h264_data,
- 0, // pts in microseconds
- 0, // dts in microseconds
- 33333, // duration in microseconds (1/30 fps)
- true, // is_keyframe
- &mut output,
- )?;
-
- // Finish the muxer (doesn't write trailer)
- h264_muxer.finish()?;
-
- // Write the trailer (this would be done by MP4File::finish())
- output.write_trailer()?;
-
- Ok(())
- }
-
- /// Example showing how this would integrate with an MP4File-like structure
struct MP4FileExample {
output: format::context::Output,
h264_muxer: Option<H264StreamMuxer>,
@@ -76,13 +19,8 @@ mod win {
fn new(output_path: PathBuf, video_config: MuxerConfig) -> Result<Self, ffmpeg::Error> {
let mut output = format::output(&output_path)?;
- // Add H264 stream and create muxer
let h264_muxer = H264StreamMuxer::new(&mut output, video_config)?;
- // You could add audio streams here too
- // ...
-
- // Write header after all streams are added
output.write_header()?;
Ok(Self {
@@ -92,7 +30,7 @@ mod win {
})
}
- #[cfg(windows)]
+ #[allow(dead_code)]
fn write_sample(
&mut self,
sample: &windows::Win32::Media::MediaFoundation::IMFSample,
@@ -103,20 +41,6 @@ mod win {
Ok(())
}
- fn write_h264_data(
- &mut self,
- data: &[u8],
- pts: i64,
- dts: i64,
- duration: i64,
- is_keyframe: bool,
- ) -> Result<(), ffmpeg::Error> {
- if let Some(muxer) = &mut self.h264_muxer {
- muxer.write_h264_data(data, pts, dts, duration, is_keyframe, &mut self.output)?;
- }
- Ok(())
- }
-
fn finish(&mut self) -> Result<(), ffmpeg::Error> {
if self.is_finished {
return Ok(());
@@ -127,71 +51,28 @@ mod win {
muxer.finish()?;
}
- // Write trailer
self.output.write_trailer()?;
Ok(())
}
}
- /// Alternative approach using the owned version for standalone use
- fn example_with_owned_muxer() -> Result<(), Box<dyn std::error::Error>> {
- use mediafoundation_ffmpeg::H264SampleMuxerOwned;
-
- // Initialize FFmpeg
- ffmpeg::init()?;
-
- let config = MuxerConfig {
- width: 1920,
- height: 1080,
- fps: 30,
- bitrate: 5_000_000,
- };
-
- // Create a standalone muxer that owns its output
- let mut muxer =
- H264SampleMuxerOwned::new_mp4(PathBuf::from("standalone_output.mp4"), config)?;
-
- // Write some H264 data
- let example_h264_data = vec![0, 0, 0, 1, 0x65]; // Example keyframe NAL
- muxer.write_h264_data(
- &example_h264_data,
- 0, // pts
- 0, // dts
- 33333, // duration
- true, // is_keyframe
- )?;
+ pub fn main() {
+ ffmpeg::init().unwrap();
- // The muxer automatically finishes and writes trailer when dropped
- muxer.finish()?;
-
- Ok(())
- }
-
- fn main() -> Result<(), Box<dyn std::error::Error>> {
- println!("Example 1: Using H264StreamMuxer with shared output");
- example_with_shared_output()?;
-
- println!("\nExample 2: Using H264SampleMuxerOwned for standalone use");
- example_with_owned_muxer()?;
-
- println!("\nExample 3: Using MP4FileExample with integrated muxer");
+ println!("Creating MP4FileExample...");
let mut mp4_file = MP4FileExample::new(
- PathBuf::from("integrated_output.mp4"),
+ PathBuf::from("example_output.mp4"),
MuxerConfig {
width: 1920,
height: 1080,
fps: 30,
bitrate: 5_000_000,
+ ..Default::default()
},
- )?;
-
- // Write some test data
- let example_h264_data = vec![0, 0, 0, 1, 0x65];
- mp4_file.write_h264_data(&example_h264_data, 0, 0, 33333, true)?;
-
- // Finish writing
- mp4_file.finish()?;
+ )
+ .unwrap();
- Ok(())
+ mp4_file.finish().unwrap();
+ println!("Done!");
}
}
diff --git a/crates/scap-ffmpeg/examples/cli.rs b/crates/scap-ffmpeg/examples/cli.rs
index 6b329ee63..053bccc13 100644
--- a/crates/scap-ffmpeg/examples/cli.rs
+++ b/crates/scap-ffmpeg/examples/cli.rs
@@ -3,33 +3,43 @@ pub async fn main() {
#[cfg(windows)]
{
use scap_direct3d::*;
+ use scap_targets::Display;
+ use std::time::Duration;
- let display = Display::primary().unwrap();
+ let display = Display::primary();
- let capturer = Capturer::new(
- display.try_as_capture_item().unwrap(),
+ let mut capturer = Capturer::new(
+ display.raw_handle().try_as_capture_item().unwrap(),
Settings {
is_border_required: Some(true),
is_cursor_capture_enabled: Some(true),
pixel_format: PixelFormat::R8G8B8A8Unorm,
+ ..Default::default()
},
- );
-
- let capture_handle = capturer
- .start(|frame| {
+ |frame| {
use scap_ffmpeg::AsFFmpeg;
let ff_frame = frame.as_ffmpeg()?;
- dbg!(ff_frame.width(), ff_frame.height(), ff_frame.format());
+ println!(
+ "Frame: {}x{} format={:?}",
+ ff_frame.width(),
+ ff_frame.height(),
+ ff_frame.format()
+ );
Ok(())
- })
- .unwrap();
+ },
+ || Ok(()),
+ None,
+ )
+ .unwrap();
+
+ capturer.start().unwrap();
std::thread::sleep(Duration::from_secs(3));
- capture_handle.stop().unwrap();
+ capturer.stop().unwrap();
std::thread::sleep(Duration::from_secs(3));
}