Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

macos hardware acceleration

Brendan Allance1e71497c9b
diff --git a/Cargo.lock b/Cargo.lock
index 8c7bfe3e5..7503f421e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -916,6 +916,8 @@ dependencies = [
"cap-ffmpeg",
"cap-project",
"ffmpeg-next",
+ "ffmpeg-sys-next",
+ "futures",
"futures-intrusive",
"lru",
"nix 0.29.0",
diff --git a/apps/desktop-solid/src-tauri/src/display.rs b/apps/desktop-solid/src-tauri/src/display.rs
index 411d5bb33..ff46ecb8a 100644
--- a/apps/desktop-solid/src-tauri/src/display.rs
+++ b/apps/desktop-solid/src-tauri/src/display.rs
@@ -90,7 +90,7 @@ pub async fn start_capturing(
_ => None,
};
- let excluded_titles = vec!["Cap", "Cap Camera", "Cap Recordings"];
+ let excluded_titles = ["Cap", "Cap Camera", "Cap Recordings"];
let excluded_targets: Vec<scap::Target> = targets
.into_iter()
.filter(|target| match target {
diff --git a/apps/desktop-solid/src-tauri/src/editor_instance.rs b/apps/desktop-solid/src-tauri/src/editor_instance.rs
index 4eb886fa1..125b1e716 100644
--- a/apps/desktop-solid/src-tauri/src/editor_instance.rs
+++ b/apps/desktop-solid/src-tauri/src/editor_instance.rs
@@ -1,10 +1,12 @@
use crate::playback::{self, PlaybackHandle};
use crate::{editor, AudioData};
use cap_project::ProjectConfiguration;
-use cap_rendering::decoder::{AsyncVideoDecoder, AsyncVideoDecoderHandle};
-use cap_rendering::{ProjectUniforms, RenderOptions, RenderVideoConstants};
+use cap_rendering::decoder::AsyncVideoDecoder;
+use cap_rendering::{
+ ProjectUniforms, RecordingDecoders, RenderOptions, RenderVideoConstants,
+};
use std::ops::Deref;
-use std::sync::atomic::{AtomicBool, Ordering};
+use std::sync::atomic::AtomicBool;
use std::{path::PathBuf, process::Command, sync::Arc};
use tokio::sync::{mpsc, watch, Mutex};
@@ -18,10 +20,9 @@ pub struct EditorState {
pub struct EditorInstance {
pub path: PathBuf,
pub id: String,
- pub screen_decoder: AsyncVideoDecoderHandle,
- pub camera_decoder: Option<AsyncVideoDecoderHandle>,
pub audio: Option<AudioData>,
pub ws_port: u16,
+ pub decoders: RecordingDecoders,
pub renderer: Arc<editor::RendererHandle>,
pub render_constants: Arc<RenderVideoConstants>,
pub state: Mutex<EditorState>,
@@ -106,8 +107,7 @@ impl EditorInstance {
let this = Arc::new(Self {
id: video_id,
path: project_path,
- screen_decoder,
- camera_decoder,
+ decoders: RecordingDecoders::new(screen_decoder, camera_decoder),
ws_port,
renderer,
render_constants,
@@ -152,8 +152,7 @@ impl EditorInstance {
audio: self.audio.clone(),
renderer: self.renderer.clone(),
render_constants: self.render_constants.clone(),
- screen_decoder: self.screen_decoder.clone(),
- camera_decoder: self.camera_decoder.clone(),
+ decoders: self.decoders.clone(),
start_frame_number,
project,
}
@@ -200,15 +199,12 @@ impl EditorInstance {
continue;
};
- let Some(screen_frame) = self.screen_decoder.get_frame(frame_number).await else {
+ let Some((screen_frame, camera_frame)) =
+ self.decoders.get_frames(frame_number).await
+ else {
return;
};
- let camera_frame = match &self.camera_decoder {
- Some(d) => d.get_frame(frame_number).await,
- None => None,
- };
-
self.renderer
.render_frame(
screen_frame,
diff --git a/apps/desktop-solid/src-tauri/src/lib.rs b/apps/desktop-solid/src-tauri/src/lib.rs
index 037f4d6b3..072fdd667 100644
--- a/apps/desktop-solid/src-tauri/src/lib.rs
+++ b/apps/desktop-solid/src-tauri/src/lib.rs
@@ -11,7 +11,7 @@ mod tray;
use camera::{create_camera_window, list_cameras};
use cap_ffmpeg::ffmpeg_path_as_str;
use cap_project::ProjectConfiguration;
-use cap_rendering::{decoder::AsyncVideoDecoderHandle, RenderOptions};
+use cap_rendering::{RecordingDecoders, RenderOptions};
use display::{list_capture_windows, Bounds, CaptureTarget};
use editor_instance::{EditorInstance, EditorState};
use ffmpeg_sidecar::{
@@ -21,7 +21,7 @@ use ffmpeg_sidecar::{
version::ffmpeg_version,
};
use image::{ImageBuffer, Rgba};
-use mp4::{Error as Mp4Error, Mp4Reader};
+use mp4::Mp4Reader;
use num_traits::ToBytes;
use objc2_app_kit::NSScreenSaverWindowLevel;
use recording::{DisplaySource, InProgressRecording};
@@ -284,8 +284,7 @@ async fn get_rendered_video(
editor_instance.render_constants.options.clone(),
project,
output_path.clone(),
- editor_instance.screen_decoder.clone(),
- editor_instance.camera_decoder.clone(),
+ editor_instance.decoders.clone(),
|_| {},
editor_instance.audio.clone(),
)
@@ -319,8 +318,7 @@ async fn render_to_file_impl(
options: RenderOptions,
project: ProjectConfiguration,
output_path: PathBuf,
- screen_recording_decoder: AsyncVideoDecoderHandle,
- camera_recording_decoder: Option<AsyncVideoDecoderHandle>,
+ decoders: RecordingDecoders,
on_progress: impl Fn(u32) + Send + 'static,
audio: Option<AudioData>,
) -> Result<PathBuf, String> {
@@ -418,8 +416,8 @@ async fn render_to_file_impl(
// Save the first frame as a screenshot
if let Some(frame_data) = first_frame {
- let width = options.output_size.0 as u32;
- let height = options.output_size.1 as u32;
+ let width = options.output_size.0;
+ let height = options.output_size.1;
let rgba_img: ImageBuffer<Rgba<u8>, Vec<u8>> =
ImageBuffer::from_raw(width, height, frame_data)
.expect("Failed to create image from frame data");
@@ -446,14 +444,7 @@ async fn render_to_file_impl(
println!("Rendering video to channel");
- cap_rendering::render_video_to_channel(
- options,
- project,
- tx_image_data,
- screen_recording_decoder,
- camera_recording_decoder,
- )
- .await?;
+ cap_rendering::render_video_to_channel(options, project, tx_image_data, decoders).await?;
println!("Copying file to {:?}", recording_dir);
let result_path = recording_dir.join("output/result.mp4");
@@ -465,10 +456,7 @@ async fn render_to_file_impl(
Err(_) => return false,
};
let reader = std::io::BufReader::new(file);
- match Mp4Reader::read_header(reader, file_size) {
- Ok(_) => true,
- Err(_) => false,
- }
+ Mp4Reader::read_header(reader, file_size).is_ok()
} else {
false
}
@@ -937,8 +925,7 @@ async fn render_to_file(
editor_instance.render_constants.options.clone(),
project,
output_path,
- editor_instance.screen_decoder.clone(),
- editor_instance.camera_decoder.clone(),
+ editor_instance.decoders.clone(),
move |current_frame| {
if current_frame == 0 {
progress_channel
@@ -1045,7 +1032,7 @@ pub fn run() {
#[cfg(all(desktop))]
{
let handle = app.handle();
- tray::create_tray(&handle)?;
+ tray::create_tray(handle)?;
}
if let Err(_error) = handle_ffmpeg_installation() {
diff --git a/apps/desktop-solid/src-tauri/src/playback.rs b/apps/desktop-solid/src-tauri/src/playback.rs
index b14896547..f265fdb72 100644
--- a/apps/desktop-solid/src-tauri/src/playback.rs
+++ b/apps/desktop-solid/src-tauri/src/playback.rs
@@ -1,7 +1,7 @@
use std::{sync::Arc, time::Duration};
use cap_project::ProjectConfiguration;
-use cap_rendering::{decoder::AsyncVideoDecoderHandle, ProjectUniforms, RenderVideoConstants};
+use cap_rendering::{ProjectUniforms, RecordingDecoders, RenderVideoConstants};
use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
SampleFormat, SizedSample,
@@ -14,8 +14,7 @@ pub struct Playback {
pub audio: Option<AudioData>,
pub renderer: Arc<editor::RendererHandle>,
pub render_constants: Arc<RenderVideoConstants>,
- pub screen_decoder: AsyncVideoDecoderHandle,
- pub camera_decoder: Option<AsyncVideoDecoderHandle>,
+ pub decoders: RecordingDecoders,
pub start_frame_number: u32,
pub project: ProjectConfiguration,
}
@@ -73,12 +72,7 @@ impl Playback {
_ = stop_rx.changed() => {
break;
},
- Some(screen_frame) = self.screen_decoder.get_frame(frame_number) => {
- let camera_frame = match &self.camera_decoder {
- Some(d) => d.get_frame(frame_number).await,
- None => None,
- };
-
+ Some((screen_frame, camera_frame)) = self.decoders.get_frames(frame_number) => {
self
.renderer
.render_frame(
diff --git a/apps/desktop-solid/src-tauri/src/tray.rs b/apps/desktop-solid/src-tauri/src/tray.rs
index b664e46ae..a303b084b 100644
--- a/apps/desktop-solid/src-tauri/src/tray.rs
+++ b/apps/desktop-solid/src-tauri/src/tray.rs
@@ -2,8 +2,7 @@ use tauri::{
image::Image,
menu::{Menu, MenuItem},
path::BaseDirectory,
- tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
- App, AppHandle, Manager, Runtime,
+ tray::TrayIconBuilder, AppHandle, Manager, Runtime,
};
pub fn create_tray<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<()> {
diff --git a/apps/desktop-solid/src/routes/editor/Editor.tsx b/apps/desktop-solid/src/routes/editor/Editor.tsx
index 8cbb160b6..eb57a04e4 100644
--- a/apps/desktop-solid/src/routes/editor/Editor.tsx
+++ b/apps/desktop-solid/src/routes/editor/Editor.tsx
@@ -96,20 +96,16 @@ function Inner() {
commands.createEditorInstance(videoId()).then((result) => {
if (result.status !== "ok") return;
const ws = new WebSocket(`ws://localhost:${result.data}/frames-ws`);
-
ws.binaryType = "arraybuffer";
-
ws.onmessage = (event) => {
const ctx = canvasRef()?.getContext("2d");
if (!ctx) return;
-
const clamped = new Uint8ClampedArray(event.data);
const imageData = new ImageData(
clamped,
OUTPUT_SIZE.width,
OUTPUT_SIZE.height
);
-
ctx.putImageData(imageData, 0, 0);
};
});
diff --git a/crates/rendering/Cargo.toml b/crates/rendering/Cargo.toml
index b69c6f4c0..b1222a6e0 100644
--- a/crates/rendering/Cargo.toml
+++ b/crates/rendering/Cargo.toml
@@ -18,3 +18,5 @@ nix = { version = "0.29.0", features = ["fs"] }
serde_json = "1.0.127"
ffmpeg-next = "7.0.4"
lru = "0.12.4"
+ffmpeg-sys-next = "7.0.2"
+futures = "0.3.30"
diff --git a/crates/rendering/src/decoder.rs b/crates/rendering/src/decoder.rs
index 648c21db9..05c574ab0 100644
--- a/crates/rendering/src/decoder.rs
+++ b/crates/rendering/src/decoder.rs
@@ -1,11 +1,21 @@
use std::{
+ cell::Cell,
collections::BTreeMap,
path::PathBuf,
+ ptr::{null, null_mut},
sync::{mpsc, Arc},
};
use ffmpeg_next::{
- format::context::input::PacketIter, frame, rescale, Packet, Rational, Rescale, Stream,
+ codec,
+ format::{self, context::input::PacketIter, Pixel},
+ frame::{self, Video},
+ rescale, Codec, Packet, Rational, Rescale, Stream,
+};
+use ffmpeg_sys_next::{
+ av_buffer_ref, av_buffer_unref, av_hwdevice_ctx_create, av_hwframe_transfer_data,
+ avcodec_find_decoder, avcodec_get_hw_config, AVBufferRef, AVCodecContext, AVHWDeviceType,
+ AVPixelFormat, AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
};
pub type DecodedFrame = Arc<Vec<u8>>;
@@ -36,23 +46,43 @@ impl AsyncVideoDecoder {
.best(ffmpeg_next::media::Type::Video)
.ok_or("Could not find a video stream")
.unwrap();
+
+ let decoder_codec =
+ ff_find_decoder(&input, &input_stream, input_stream.parameters().id()).unwrap();
+
+ let mut context = codec::context::Context::new_with_codec(decoder_codec);
+ context.set_parameters(input_stream.parameters()).unwrap();
+
+ let hw_device = {
+ #[cfg(target_os = "macos")]
+ {
+ context
+ .try_use_hw_device(
+ AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
+ Pixel::NV12,
+ )
+ .ok()
+ }
+
+ #[cfg(not(target_os = "macos"))]
+ None
+ };
+
let input_stream_index = input_stream.index();
let time_base = input_stream.time_base();
let frame_rate = input_stream.rate();
// Create a decoder for the video stream
- let mut decoder =
- ffmpeg_next::codec::context::Context::from_parameters(input_stream.parameters())
- .unwrap()
- .decoder()
- .video()
- .unwrap();
+ let mut decoder = context.decoder().video().unwrap();
use ffmpeg_next::format::Pixel;
use ffmpeg_next::software::scaling::{context::Context, flag::Flags};
let mut scaler = Context::get(
- decoder.format(),
+ hw_device
+ .as_ref()
+ .map(|d| d.pix_fmt)
+ .unwrap_or(decoder.format()),
decoder.width(),
decoder.height(),
Pixel::RGBA,
@@ -97,25 +127,24 @@ impl AsyncVideoDecoder {
Some(sender)
};
- // need to seek when frame_number is less than last_decoded_frame
-
- let cache_min = frame_number
- .checked_sub(FRAME_CACHE_SIZE as u32 / 2)
- .unwrap_or(0);
+ let cache_min = frame_number.saturating_sub(FRAME_CACHE_SIZE as u32 / 2);
let cache_max = frame_number + FRAME_CACHE_SIZE as u32 / 2;
- // TODO: seek forward when last_decoded_frame's I-frame is previous to frame_number's I-frame
if frame_number <= 0
|| last_decoded_frame
- .map(|f| frame_number < f)
- .unwrap_or(false)
+ .map(|f| {
+ frame_number < f ||
+ // seek forward for big jumps. this threshold is arbitrary but should be derived from i-frames in future
+ frame_number - f > FRAME_CACHE_SIZE as u32
+ })
+ .unwrap_or(true)
{
let timestamp_us =
((frame_number as f32 / frame_rate.numerator() as f32)
* 1_000_000.0) as i64;
let position = timestamp_us.rescale((1, 1_000_000), rescale::TIME_BASE);
- // println!("seeking to {position} for frame {frame_number}");
+ println!("seeking to {position} for frame {frame_number}");
drop(packet_stuff);
@@ -171,8 +200,11 @@ impl AsyncVideoDecoder {
// !too_great_for_cache_bounds && !too_small_for_cache_bounds
// );
+ let sw_frame = try_transfer_hwframe(&temp_frame);
+ let frame = sw_frame.as_ref().unwrap_or(&temp_frame);
+
let mut rgb_frame = frame::Video::empty();
- scaler.run(&temp_frame, &mut rgb_frame).unwrap();
+ scaler.run(frame, &mut rgb_frame).unwrap();
let frame = Arc::new(rgb_frame.data(0).to_vec());
@@ -279,3 +311,140 @@ impl<T> PeekableReceiver<T> {
}
}
}
+
+thread_local! {
+ static HW_PIX_FMT: Cell<AVPixelFormat> = const { Cell::new(AVPixelFormat::AV_PIX_FMT_NONE) };
+}
+
+unsafe extern "C" fn get_format(
+ _: *mut AVCodecContext,
+ pix_fmts: *const AVPixelFormat,
+) -> AVPixelFormat {
+ let mut fmt = pix_fmts;
+
+ loop {
+ if *fmt == AVPixelFormat::AV_PIX_FMT_NONE {
+ break;
+ }
+
+ if *fmt == HW_PIX_FMT.get() {
+ return *fmt;
+ }
+
+ fmt = fmt.offset(1);
+ }
+
+ AVPixelFormat::AV_PIX_FMT_NONE
+}
+
+fn ff_find_decoder(
+ s: &format::context::Input,
+ st: &format::stream::Stream,
+ codec_id: codec::Id,
+) -> Option<Codec> {
+ unsafe {
+ use ffmpeg_next::media::Type;
+ let codec = match st.parameters().medium() {
+ Type::Video => Some((*s.as_ptr()).video_codec),
+ Type::Audio => Some((*s.as_ptr()).audio_codec),
+ Type::Subtitle => Some((*s.as_ptr()).subtitle_codec),
+ _ => None,
+ };
+
+ if let Some(codec) = codec {
+ if !codec.is_null() {
+ return Some(Codec::wrap(codec));
+ }
+ }
+
+ let found = avcodec_find_decoder(codec_id.into());
+
+ if found.is_null() {
+ return None;
+ }
+ Some(Codec::wrap(found))
+ }
+}
+
+fn try_transfer_hwframe(src: &Video) -> Option<Video> {
+ unsafe {
+ if src.format() == HW_PIX_FMT.get().into() {
+ let mut sw_frame = frame::Video::empty();
+
+ if av_hwframe_transfer_data(sw_frame.as_mut_ptr(), src.as_ptr(), 0) >= 0 {
+ return Some(sw_frame);
+ };
+ }
+ }
+
+ None
+}
+
+struct HwDevice {
+ pub device_type: AVHWDeviceType,
+ pub pix_fmt: Pixel,
+ ctx: *mut AVBufferRef,
+}
+
+impl Drop for HwDevice {
+ fn drop(&mut self) {
+ unsafe {
+ av_buffer_unref(&mut self.ctx);
+ }
+ }
+}
+
+trait CodecContextExt {
+ fn try_use_hw_device(
+ &mut self,
+ device_type: AVHWDeviceType,
+ pix_fmt: Pixel,
+ ) -> Result<HwDevice, &'static str>;
+}
+
+impl CodecContextExt for codec::context::Context {
+ fn try_use_hw_device(
+ &mut self,
+ device_type: AVHWDeviceType,
+ pix_fmt: Pixel,
+ ) -> Result<HwDevice, &'static str> {
+ let codec = self.codec().ok_or("no codec")?;
+
+ unsafe {
+ let mut i = 0;
+ loop {
+ let config = avcodec_get_hw_config(codec.as_ptr(), i);
+ if config.is_null() {
+ return Err("no hw config");
+ }
+
+ if (*config).methods & (AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) == 1
+ && (*config).device_type == AVHWDeviceType::AV_HWDEVICE_TYPE_VIDEOTOOLBOX
+ {
+ HW_PIX_FMT.set((*config).pix_fmt);
+ break;
+ }
+
+ i += 1;
+ }
+
+ let context = self.as_mut_ptr();
+
+ (*context).get_format = Some(get_format);
+
+ let mut hw_device_ctx = null_mut();
+
+ if av_hwdevice_ctx_create(&mut hw_device_ctx, device_type, null(), null_mut(), 0) < 0 {
+ return Err("failed to create hw device context");
+ }
+
+ (*context).hw_device_ctx = av_buffer_ref(hw_device_ctx);
+
+ Ok(HwDevice {
+ device_type,
+ ctx: hw_device_ctx,
+ pix_fmt,
+ })
+ }
+ }
+}
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 014b0ed28..7b77e5bd6 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -1,6 +1,7 @@
use anyhow::Result;
use bytemuck::{Pod, Zeroable};
use decoder::AsyncVideoDecoderHandle;
+use futures::future::OptionFuture;
use futures_intrusive::channel::shared::oneshot_channel;
use serde::{Deserialize, Serialize};
use specta::Type;
@@ -92,27 +93,26 @@ impl From<BackgroundSource> for Background {
}
}
-#[derive(Debug, Clone, Copy)]
-pub struct UV<T> {
- pub u: T,
- pub v: T,
+#[derive(Clone)]
+pub struct RecordingDecoders {
+ screen: AsyncVideoDecoderHandle,
+ camera: Option<AsyncVideoDecoderHandle>,
}
-impl<T> UV<T> {
- pub fn new(x: T, y: T) -> Self {
- Self { u: x, v: y }
+impl RecordingDecoders {
+ pub fn new(screen: AsyncVideoDecoderHandle, camera: Option<AsyncVideoDecoderHandle>) -> Self {
+ RecordingDecoders { screen, camera }
}
-}
-
-impl<T> From<UV<T>> for (T, T) {
- fn from(xy: UV<T>) -> Self {
- (xy.u, xy.v)
- }
-}
+ pub async fn get_frames(
+ &self,
+ frame_number: u32,
+ ) -> Option<(DecodedFrame, Option<DecodedFrame>)> {
+ let (screen_frame, camera_frame) = tokio::join!(
+ self.screen.get_frame(frame_number),
+ OptionFuture::from(self.camera.as_ref().map(|d| d.get_frame(frame_number)))
+ );
-impl<T> From<UV<T>> for [T; 2] {
- fn from(xy: UV<T>) -> Self {
- [xy.u, xy.v]
+ screen_frame.map(|f| (f, camera_frame.flatten()))
}
}
@@ -120,8 +120,7 @@ pub async fn render_video_to_channel(
options: RenderOptions,
project: ProjectConfiguration,
sender: tokio::sync::mpsc::UnboundedSender<Vec<u8>>,
- screen_recording_decoder: AsyncVideoDecoderHandle,
- camera_recording_decoder: Option<AsyncVideoDecoderHandle>,
+ decoders: RecordingDecoders,
) -> Result<(), String> {
let constants = RenderVideoConstants::new(options).await?;
@@ -137,7 +136,7 @@ pub async fn render_video_to_channel(
let mut i = 0;
loop {
- match screen_recording_decoder.get_frame(i).await {
+ match decoders.screen.get_frame(i).await {
Some(frame) => {
if screen_tx.send(frame).is_err() {
println!("Error sending screen frame to renderer");
@@ -155,7 +154,7 @@ pub async fn render_video_to_channel(
println!("done decoding screen in {:.2?}", now.elapsed())
});
- let mut camera_rx = camera_recording_decoder.map(|camera_recording_decoder| {
+ let mut camera_rx = decoders.camera.map(|decoder| {
println!("Setting up FFmpeg input for webcam recording...");
let (camera_tx, camera_rx) = tokio::sync::mpsc::unbounded_channel();
@@ -164,7 +163,7 @@ pub async fn render_video_to_channel(
let mut i = 0;
loop {
- match camera_recording_decoder.get_frame(i).await {
+ match decoder.get_frame(i).await {
Some(frame) => {
if camera_tx.send(frame).is_err() {
println!("Error sending screen frame to renderer");
@@ -359,7 +358,7 @@ impl ProjectUniforms {
let frame_aspect = frame_size[0] / frame_size[1];
let min_axis = frame_size[0].min(frame_size[1]);
let y_padding =
- project.background.padding as f32 / 100.0 * SCREEN_MAX_PADDING * output_size[1];
+ project.background.padding / 100.0 * SCREEN_MAX_PADDING * output_size[1];
let target_height = (output_size[1] - y_padding) - y_padding;
let target_width = target_height * frame_aspect;
@@ -379,7 +378,7 @@ impl ProjectUniforms {
crop_bounds: [0.0, 0.0, frame_size[0], frame_size[1]],
target_bounds,
target_size,
- rounding_px: project.background.rounding as f32 / 100.0 * 0.5 * min_target_axis,
+ rounding_px: project.background.rounding / 100.0 * 0.5 * min_target_axis,
..Default::default()
}
};
@@ -431,7 +430,7 @@ impl ProjectUniforms {
target_bounds[2] - target_bounds[0],
target_bounds[3] - target_bounds[1],
],
- rounding_px: project.camera.rounding as f32 / 100.0 * 0.5 * size[0],
+ rounding_px: project.camera.rounding / 100.0 * 0.5 * size[0],
mirror_x: if project.camera.mirror { 1.0 } else { 0.0 },
..Default::default()
}
diff --git a/crates/rendering/src/main.rs b/crates/rendering/src/main.rs
index 05e904d77..adafddb79 100644
--- a/crates/rendering/src/main.rs
+++ b/crates/rendering/src/main.rs
@@ -1,45 +1,44 @@
-use std::path::PathBuf;
-use cap_project::{BackgroundSource, ProjectConfiguration, RecordingMeta};
+// use cap_project::{BackgroundSource, ProjectConfiguration, RecordingMeta};
#[tokio::main]
async fn main() {
- let project_path = PathBuf::from(
- r#"/Users/brendonovich/Library/Application Support/so.cap.desktop-solid/recordings/414f2abd-8186-479f-85e7-08a64411a33c.cap"#,
- );
+ // let project_path = PathBuf::from(
+ // r#"/Users/brendonovich/Library/Application Support/so.cap.desktop-solid/recordings/414f2abd-8186-479f-85e7-08a64411a33c.cap"#,
+ // );
- let mut project: ProjectConfiguration = ProjectConfiguration::default();
+ // let mut project: ProjectConfiguration = ProjectConfiguration::default();
- project.camera.position.x = cap_project::CameraXPosition::Right;
- project.camera.position.y = cap_project::CameraYPosition::Top;
- project.camera.rounding = 0;
- project.camera.mirror = false;
+ // project.camera.position.x = cap_project::CameraXPosition::Right;
+ // project.camera.position.y = cap_project::CameraYPosition::Top;
+ // project.camera.rounding = 0;
+ // project.camera.mirror = false;
- project.background.source = BackgroundSource::Gradient {
- from: [71, 133, 255],
- to: [255, 71, 102],
- };
- project.background.rounding = 0;
- project.background.padding = 0;
+ // project.background.source = BackgroundSource::Gradient {
+ // from: [71, 133, 255],
+ // to: [255, 71, 102],
+ // };
+ // project.background.rounding = 0;
+ // project.background.padding = 0;
- let meta: RecordingMeta = serde_json::from_str(
- &std::fs::read_to_string(project_path.join("recording-meta.json")).unwrap(),
- )
- .unwrap();
+ // let meta: RecordingMeta = serde_json::from_str(
+ // &std::fs::read_to_string(project_path.join("recording-meta.json")).unwrap(),
+ // )
+ // .unwrap();
- render_video_to_file(
- cap_rendering::RenderOptions {
- camera_size: meta.camera.map(|c| (c.width, c.height)),
- screen_size: (meta.display.width, meta.display.height),
- output_size: (1920, 1080),
- },
- project,
- project_path.join("output/result.mp4"),
- VideoDecoderActor::new(project_path.join("content/display.mp4").clone()),
- meta.camera
- .map(|_| VideoDecoderActor::new(project_path.join("content/camera.mp4").clone())),
- |_| {},
- )
- .await
- .ok();
+ // render_video_to_file(
+ // cap_rendering::RenderOptions {
+ // camera_size: meta.camera.map(|c| (c.width, c.height)),
+ // screen_size: (meta.display.width, meta.display.height),
+ // output_size: (1920, 1080),
+ // },
+ // project,
+ // project_path.join("output/result.mp4"),
+ // VideoDecoderActor::new(project_path.join("content/display.mp4").clone()),
+ // meta.camera
+ // .map(|_| VideoDecoderActor::new(project_path.join("content/camera.mp4").clone())),
+ // |_| {},
+ // )
+ // .await
+ // .ok();
}