-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy path10_recording_output.rs
More file actions
107 lines (92 loc) · 3.79 KB
/
Copy path10_recording_output.rs
File metadata and controls
107 lines (92 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Recording Output Example
//!
//! Demonstrates direct video file recording (macOS 15.0+).
//! This example shows:
//! - Creating recording output configuration
//! - Setting video codec (H.264/HEVC)
//! - Setting output file type (MP4/MOV)
//! - Querying available codecs and file types
//! - Getting recording duration and file size
//!
//! Run with: `cargo run --example 10_recording_output --features macos_15_0`
#![allow(clippy::unnecessary_wraps)]
#[cfg(not(feature = "macos_15_0"))]
fn main() {
eprintln!("This example requires the 'macos_15_0' feature flag.");
eprintln!("Run with: cargo run --example 10_recording_output --features macos_15_0");
}
#[cfg(feature = "macos_15_0")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
use screencapturekit::recording_output::{
SCRecordingOutput, SCRecordingOutputCodec, SCRecordingOutputConfiguration,
SCRecordingOutputFileType,
};
use std::path::PathBuf;
println!("=== Recording Output Example (macOS 15.0+) ===\n");
// Create output configuration using builder pattern
let output_path = PathBuf::from("/tmp/screen_recording.mp4");
let config = SCRecordingOutputConfiguration::new()
.with_output_url(&output_path)
.with_video_codec(SCRecordingOutputCodec::H264)
.with_output_file_type(SCRecordingOutputFileType::MP4);
println!("📁 Output path: {}", output_path.display());
println!("🎬 Video codec: {:?}", config.video_codec());
println!("📄 File type: {:?}", config.output_file_type());
// Query available options
println!("\n📋 Available Options:");
println!(
" Video codecs available: {}",
config.available_video_codecs_count()
);
println!(
" File types available: {}",
config.available_output_file_types_count()
);
// Show all codec options
println!("\n🎬 Supported Codecs:");
println!(" - H264 (value: {})", SCRecordingOutputCodec::H264 as i32);
println!(" - HEVC (value: {})", SCRecordingOutputCodec::HEVC as i32);
// Show all file type options
println!("\n📄 Supported File Types:");
println!(
" - MP4 (value: {})",
SCRecordingOutputFileType::MP4 as i32
);
println!(
" - MOV (value: {})",
SCRecordingOutputFileType::MOV as i32
);
// Create recording output
println!("\n🎥 Creating recording output...");
if let Some(recording_output) = SCRecordingOutput::new(&config) {
println!(" ✅ Recording output created successfully!");
// Get current recording stats (will be 0 since not recording)
let duration = recording_output.recorded_duration();
let file_size = recording_output.recorded_file_size();
println!("\n📊 Recording Stats:");
println!(
" Duration: {}/{} seconds",
duration.value, duration.timescale
);
println!(" File size: {file_size} bytes");
// Test cloning
let _cloned = recording_output;
println!("\n 📋 Clone test: passed");
} else {
println!(" ⚠️ Recording output creation failed.");
println!(" This may happen if macOS 15.0+ is not available.");
}
// Test configuration cloning and debug
let config_clone = config;
println!("\n📋 Configuration Debug:");
println!(" {config_clone:?}");
// Test with HEVC and MOV
println!("\n🔄 Testing HEVC + MOV configuration...");
let hevc_config = SCRecordingOutputConfiguration::new()
.with_video_codec(SCRecordingOutputCodec::HEVC)
.with_output_file_type(SCRecordingOutputFileType::MOV);
println!(" Codec: {:?}", hevc_config.video_codec());
println!(" File type: {:?}", hevc_config.output_file_type());
println!("\n✅ Recording output example completed!");
Ok(())
}