Skip to content

Commit

Permalink
separate cap-editor crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Oct 8, 2024
1 parent 60cfb6b commit 70919c9
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 98 deletions.
62 changes: 47 additions & 15 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ members = [
"crates/ffmpeg",
"crates/utils",
"crates/project",
"crates/editor",
]

[workspace.dependencies]
ffmpeg-next = { git = "https://github.com/CapSoftware/rust-ffmpeg", rev = "11f8d264bbc0" }
ffmpeg = { package = "ffmpeg-next", git = "https://github.com/CapSoftware/rust-ffmpeg", rev = "11f8d264bbc0" }
tauri = { version = "2.0.0-rc" }
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cpal = "0.15.3"
indexmap = "2.5.0"
num-traits = "0.2.19"
tempfile = "3.12.0"
ffmpeg-next.workspace = true
ffmpeg.workspace = true
chrono = "0.4.38"
rodio = "0.19.0"
fast_image_resize = "4.2.1"
Expand All @@ -74,6 +74,7 @@ cap-utils = { path = "../../../crates/utils" }
cap-project = { path = "../../../crates/project" }
cap-rendering = { path = "../../../crates/rendering" }
cap-ffmpeg = { path = "../../../crates/ffmpeg" }
cap-editor = { path = "../../../crates/editor" }
reqwest = { version = "0.12.7", features = ["json", "stream", "multipart"] }
dotenvy_macro = "0.15.7"
global-hotkey = "0.5.5"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
Device, SampleFormat, SizedSample, Stream, StreamConfig, SupportedStreamConfig,
};
use ffmpeg_next as ffmpeg;

use indexmap::IndexMap;
use num_traits::ToBytes;
use std::{fs::File, io::Write, path::PathBuf, sync::Arc, time::Instant};
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src-tauri/src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ffmpeg_next as ffmpeg;
use serde::Serialize;
use specta::Type;
use std::{
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ffmpeg_next::{format as avformat, frame::Video, software};
use ffmpeg::{format as avformat, frame::Video, software};
use std::{
path::PathBuf,
time::{Instant, SystemTime},
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use ffmpeg_next::{self as ffmpeg, Dictionary};
use ffmpeg::{self as ffmpeg, Dictionary};

macro_rules! dict {
( $($key:expr => $value:expr),* $(,)*) => ({
Expand Down
27 changes: 6 additions & 21 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,36 @@ mod auth;
mod camera;
mod capture;
mod display;
mod editor;
mod editor_instance;
mod encoder;
mod flags;
mod general_settings;
mod hotkeys;
mod macos;
mod notifications;
mod permissions;
mod playback;
mod project_recordings;
mod recording;
mod tray;
mod upload;
mod web_api;

use audio::AppSounds;
use auth::AuthStore;
use camera::{create_camera_window, find_camera_by_label, list_cameras, CameraFeed};
use camera::{create_camera_window, list_cameras, CameraFeed};
use cap_editor::{AudioData, EditorState, ProjectRecordings};
use cap_editor::{EditorInstance, FRAMES_WS_PATH};
use cap_ffmpeg::FFmpeg;
use cap_project::{
ProjectConfiguration, RecordingMeta, SharingMeta, TimelineConfiguration, TimelineSegment,
};
use cap_rendering::ProjectUniforms;
use cap_utils::create_named_pipe;
use display::{list_capture_windows, Bounds, CaptureTarget, FPS};
use editor_instance::{EditorInstance, EditorState, FRAMES_WS_PATH};
use general_settings::GeneralSettingsStore;
use image::{ImageBuffer, Rgba};
use mp4::Mp4Reader;
use num_traits::ToBytes;
use objc2_app_kit::NSScreenSaverWindowLevel;
use png::{ColorType, Encoder};
use project_recordings::ProjectRecordings;
use recording::{DisplaySource, InProgressRecording};
use scap::capturer::Capturer;
use scap::frame::Frame;
Expand All @@ -46,8 +42,7 @@ use specta::Type;
use std::fs::File;
use std::io::BufWriter;
use std::io::{BufReader, Write};
use std::sync::atomic::AtomicU16;
use std::time::{Instant, SystemTime, UNIX_EPOCH};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{
collections::HashMap, marker::PhantomData, path::PathBuf, process::Command, sync::Arc,
time::Duration,
Expand All @@ -58,16 +53,13 @@ use tauri_plugin_decorum::WebviewWindowExt;
use tauri_plugin_notification::PermissionState;
use tauri_plugin_shell::ShellExt;
use tauri_specta::Event;
use tokio::io::AsyncWriteExt;
use tokio::sync::{mpsc, oneshot, watch};
use tokio::sync::watch;
use tokio::task;
use tokio::{
sync::{Mutex, RwLock},
time::sleep,
};
use upload::{
upload_audio, upload_image, upload_individual_file, upload_video, UploadedAudio, UploadedVideo,
};
use upload::{upload_image, upload_individual_file, upload_video};

#[derive(specta::Type, Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -951,13 +943,6 @@ impl EditorStateChanged {
}
}

#[derive(Clone)]
pub struct AudioData {
pub buffer: Arc<Vec<f64>>,
pub sample_rate: u32,
// pub channels: u18
}

#[tauri::command]
#[specta::specta]
async fn start_playback(app: AppHandle, video_id: String) {
Expand Down
12 changes: 6 additions & 6 deletions apps/desktop/src-tauri/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ fn build_video_upload_body(
base: S3UploadBody,
) -> Result<S3VideoUploadBody, String> {
let input =
ffmpeg_next::format::input(path).map_err(|e| format!("Failed to read input file: {e}"))?;
ffmpeg::format::input(path).map_err(|e| format!("Failed to read input file: {e}"))?;
let stream = input
.streams()
.best(ffmpeg_next::media::Type::Video)
.best(ffmpeg::media::Type::Video)
.ok_or_else(|| "Failed to find appropriate video stream in file".to_string())?;

let duration_millis = input.duration() as f64 / 1000.;

let codec = ffmpeg_next::codec::context::Context::from_parameters(stream.parameters())
let codec = ffmpeg::codec::context::Context::from_parameters(stream.parameters())
.map_err(|e| format!("Unable to read video codec information: {e}"))?;
let codec_name = codec.id();
let video = codec.decoder().video().unwrap();
Expand All @@ -536,15 +536,15 @@ fn build_audio_upload_body(
base: S3UploadBody,
) -> Result<S3AudioUploadBody, String> {
let input =
ffmpeg_next::format::input(path).map_err(|e| format!("Failed to read input file: {e}"))?;
ffmpeg::format::input(path).map_err(|e| format!("Failed to read input file: {e}"))?;
let stream = input
.streams()
.best(ffmpeg_next::media::Type::Audio)
.best(ffmpeg::media::Type::Audio)
.ok_or_else(|| "Failed to find appropriate audio stream in file".to_string())?;

let duration_millis = input.duration() as f64 / 1000.;

let codec = ffmpeg_next::codec::context::Context::from_parameters(stream.parameters())
let codec = ffmpeg::codec::context::Context::from_parameters(stream.parameters())
.map_err(|e| format!("Unable to read audio codec information: {e}"))?;
let codec_name = codec.id();

Expand Down
9 changes: 1 addition & 8 deletions apps/desktop/src/routes/(window-chrome)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,7 @@ export default function () {
: "bg-red-50 text-red-300"
)}
onPointerDown={(e) => {
const permission = permissions?.data?.camera;

if (
permission !== "granted" &&
permission !== "notNeeded"
) {
e.stopPropagation();
}
e.stopPropagation();
}}
onClick={(e) => {
e.stopPropagation();
Expand Down
18 changes: 18 additions & 0 deletions crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "cap-editor"
version = "0.1.0"
edition = "2021"

[dependencies]
cap-project = { path = "../project" }
cap-ffmpeg = { path = "../ffmpeg" }
cap-rendering = { path = "../rendering" }

tokio = { version = "1.39.2", features = ["macros", "process", "fs"] }
tracing = "0.1.40"
cpal = "0.15.3"
serde_json = "1.0.128"
axum = { version = "0.7.5", features = ["ws"] }
ffmpeg.workspace = true
specta = "=2.0.0-rc.19"
serde = { version = "1", features = ["derive"] }
8 changes: 8 additions & 0 deletions crates/editor/src/audio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::sync::Arc;

#[derive(Clone)]
pub struct AudioData {
pub buffer: Arc<Vec<f64>>,
pub sample_rate: u32,
// pub channels: u18
}
File renamed without changes.
Loading

0 comments on commit 70919c9

Please sign in to comment.