Skip to content

Commit

Permalink
fix single-segment audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Nov 27, 2024
1 parent b49d7a7 commit f0af736
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src/utils/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export type Audio = { duration: number; sample_rate: number; channels: number }
export type AudioConfiguration = { mute: boolean; improve: boolean }
export type AudioInputLevelChange = number
export type AudioMeta = { path: string }
export type AuthStore = { token: string; user_id: string; expires: number; plan: Plan | null }
export type AuthStore = { token: string; user_id: string | null; expires: number; plan: Plan | null }
export type AuthenticationInvalid = null
export type BackgroundConfiguration = { source: BackgroundSource; blur: number; padding: number; rounding: number; inset: number; crop: Crop | null }
export type BackgroundSource = { type: "wallpaper"; id: number } | { type: "image"; path: string | null } | { type: "color"; value: [number, number, number] } | { type: "gradient"; from: [number, number, number]; to: [number, number, number]; angle?: number }
Expand Down
22 changes: 11 additions & 11 deletions crates/editor/src/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ impl Playback {
.map(|t| t.duration())
.unwrap_or(f64::MAX);

// Lock the mutex and check if audio data is available
// if let Some(audio_data) = self.audio.as_ref() {
// AudioPlayback {
// audio: audio_data.clone(),
// stop_rx: stop_rx.clone(),
// start_frame_number: self.start_frame_number,
// duration,
// project: self.project.clone(),
// }
// .spawn();
// };
// TODO: make this work with >1 segment
if let Some(audio_data) = self.segments[0].audio.as_ref() {
AudioPlayback {
audio: audio_data.clone(),
stop_rx: stop_rx.clone(),
start_frame_number: self.start_frame_number,
duration,
project: self.project.clone(),
}
.spawn();
};

loop {
if frame_number as f64 > FPS as f64 * duration {
Expand Down
45 changes: 23 additions & 22 deletions crates/export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,29 @@ pub async fn export_video_to_file(

let audio_dir = tempfile::tempdir().unwrap();
let video_dir = tempfile::tempdir().unwrap();
let mut audio = None::<AudioRender>;
// if let Some(audio_data) = audio.as_ref() {
// let (tx, rx) = tokio::sync::mpsc::channel::<Vec<u8>>(30);

// let pipe_path =
// cap_utils::create_channel_named_pipe(rx, audio_dir.path().join("audio.pipe"));

// ffmpeg.add_input(cap_ffmpeg_cli::FFmpegRawAudioInput {
// input: pipe_path,
// sample_format: "f64le".to_string(),
// sample_rate: audio_data.info.sample_rate,
// channels: audio_data.info.channels as u16,
// });

// let buffer = AudioFrameBuffer::new(audio_data.clone());
// Some(AudioRender {
// buffer,
// pipe_tx: tx,
// })
// } else {
// None
// };
let mut audio = if let Some(audio_data) =
audio_segments.get(0).and_then(|d| d.as_ref().as_ref())
{
let (tx, rx) = tokio::sync::mpsc::channel::<Vec<u8>>(30);

let pipe_path =
cap_utils::create_channel_named_pipe(rx, audio_dir.path().join("audio.pipe"));

ffmpeg.add_input(cap_ffmpeg_cli::FFmpegRawAudioInput {
input: pipe_path,
sample_format: "f64le".to_string(),
sample_rate: audio_data.info.sample_rate,
channels: audio_data.info.channels as u16,
});

let buffer = AudioFrameBuffer::new(audio_data.clone());
Some(AudioRender {
buffer,
pipe_tx: tx,
})
} else {
None
};

let video_tx = {
let (tx, rx) = tokio::sync::mpsc::channel::<Vec<u8>>(30);
Expand Down

1 comment on commit f0af736

@vercel
Copy link

@vercel vercel bot commented on f0af736 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.