Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-windows-inner-size
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEeleeya committed Jan 14, 2025
2 parents 3822f7a + ddf0ca1 commit a298990
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tokio.workspace = true
editor = "0.1.1"
scap.workspace = true
core-graphics = "0.24.0"
uuid = { version = "1.11.1", features = ["v4"] }
45 changes: 43 additions & 2 deletions apps/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::{path::PathBuf, sync::Arc};
use std::{env::current_dir, path::PathBuf, sync::Arc};

use cap_editor::create_segments;
use cap_media::sources::{get_target_fps, ScreenCaptureTarget};
use cap_project::{RecordingMeta, XY};
use cap_recording::RecordingOptions;
use cap_rendering::RenderVideoConstants;
use clap::{Args, Parser, Subcommand, ValueEnum};
use tokio::io::{AsyncBufReadExt, BufReader};
use uuid::Uuid;

#[derive(Parser)]
struct Cli {
Expand Down Expand Up @@ -54,6 +57,12 @@ struct RecordStartArgs {
/// ID of the microphone to record
#[arg(long)]
mic: Option<u32>,
#[arg(long)]
/// Path to save the '.cap' project to
path: Option<PathBuf>,
/// Maximum fps to record at (max 60)
#[arg(long)]
fps: Option<u32>,
}

#[derive(Args)]
Expand Down Expand Up @@ -183,7 +192,39 @@ window {}:
})
.ok_or("No target specified".to_string())??;

dbg!(target_info);
dbg!(&target_info);

let id = Uuid::new_v4().to_string();
let path = args
.path
.unwrap_or_else(|| current_dir().unwrap().join(format!("{id}.cap")));

let actor = cap_recording::spawn_recording_actor(
id,
path,
RecordingOptions {
capture_target: target_info,
camera_label: None,
audio_input_name: None,
fps: 30,
output_resolution: None,
},
None,
None,
)
.await
.map_err(|e| e.to_string())?;

println!("Recording starting, press Enter to stop");

tokio::io::BufReader::new(tokio::io::stdin())
.read_line(&mut String::new())
.await
.unwrap();

println!("Recording stopped");

actor.stop().await.unwrap();
}
_ => {}
},
Expand Down
2 changes: 1 addition & 1 deletion crates/media/src/encoders/h264_avassetwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl H264AVAssetWriterEncoder {

let mut video_input = av::AssetWriterInput::with_media_type_and_output_settings(
av::MediaType::video(),
Some(output_settings.as_ref()),
Some(dbg!(output_settings.as_ref())),
)
.map_err(|_| MediaError::Any("Failed to create AVAssetWriterInput"))?;
video_input.set_expects_media_data_in_real_time(true);
Expand Down
2 changes: 1 addition & 1 deletion crates/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn init() -> Result<(), MediaError> {

#[derive(Error, Debug)]
pub enum MediaError {
#[error("Media error: {0}")]
#[error("{0}")]
Any(&'static str),

#[error("Cannot build a pipeline without any tasks")]
Expand Down
39 changes: 33 additions & 6 deletions crates/media/src/sources/screen_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ impl<TCaptureFormat> ScreenCaptureSource<TCaptureFormat> {

let options = this.create_options();

let [frame_width, frame_height] = get_output_frame_size(&options);
let [frame_width, frame_height] = get_output_frame_size(&dbg!(options));
dbg!(frame_width, frame_height);
this.video_info =
VideoInfo::from_raw(RawVideoFormat::Bgra, frame_width, frame_height, MAX_FPS);

Expand All @@ -147,7 +148,7 @@ impl<TCaptureFormat> ScreenCaptureSource<TCaptureFormat> {
}

fn create_options(&self) -> Options {
let targets = dbg!(scap::get_all_targets());
let targets = scap::get_all_targets();

let excluded_targets: Vec<scap::Target> = targets
.iter()
Expand All @@ -173,10 +174,36 @@ impl<TCaptureFormat> ScreenCaptureSource<TCaptureFormat> {
};

let target = match &self.target {
ScreenCaptureTarget::Window(w) => targets.into_iter().find(|t| match &t {
Target::Window(window) if window.id == w.id => true,
_ => false,
}),
ScreenCaptureTarget::Window(w) => {
let window_target = targets
.iter()
.find_map(|t| match t {
Target::Window(window) if window.id == w.id => Some(window),
_ => None,
})
.unwrap();

#[cfg(target_os = "macos")]
{
platform::display_for_window(window_target.raw_handle).and_then(|display| {
targets.into_iter().find(|t| match t {
Target::Display(d) => d.raw_handle.id == display.id,
_ => false,
})
})
}
#[cfg(target_os = "windows")]
{
platform::display_for_window(window_target.raw_handle).and_then(|display| {
targets.into_iter().find(|t| match t {
Target::Display(d) => d.raw_handle == display,
_ => false,
})
})
}
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
None
}
ScreenCaptureTarget::Screen(capture_screen) => targets
.iter()
.find(|t| match t {
Expand Down
10 changes: 7 additions & 3 deletions crates/recording/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use cap_flags::FLAGS;
use cap_media::{
data::Pixel,
encoders::{H264Encoder, MP3Encoder, Output},
feeds::{AudioInputFeed, CameraFeed},
filters::VideoFilter,
Expand Down Expand Up @@ -542,7 +543,7 @@ impl MakeCapturePipeline for cap_media::sources::CMSampleBufferCapture {
let screen_config = source.info();
let screen_encoder = cap_media::encoders::H264AVAssetWriterEncoder::init(
"screen",
screen_config,
dbg!(screen_config),
Output::File(output_path.into()),
)?;

Expand All @@ -561,8 +562,11 @@ impl MakeCapturePipeline for cap_media::sources::AVFrameCapture {
where
Self: Sized,
{
let screen_config = source.info();
let screen_filter = VideoFilter::init("screen", screen_config, screen_config)?;
let mut screen_config = source.info();
let screen_filter = VideoFilter::init("screen", screen_config, {
screen_config.pixel_format = Pixel::NV12;
screen_config
})?;
let screen_encoder =
H264Encoder::init("screen", screen_config, Output::File(output_path.into()))?;
Ok(builder
Expand Down

0 comments on commit a298990

Please sign in to comment.