Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(media): a clip's sound rendered as a file, under Generated › Processed

Jareer8434ec6b5926
diff --git a/src/crates/concat-project/src/model.rs b/src/crates/concat-project/src/model.rs
index 2dd5ba69..f5d4c6dd 100644
--- a/src/crates/concat-project/src/model.rs
+++ b/src/crates/concat-project/src/model.rs
@@ -39,6 +39,9 @@ pub enum MediaKind {
pub enum MediaOrigin {
/// Read aloud by the speech sheet.
Speech,
+ /// A clip's sound rendered as it played - trimmed, at its speed, with
+ /// its level, fades and effects baked in - as a file of its own.
+ Processed,
}
/// What a clip can be - wider than [`MediaKind`] because a text clip has no
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index d4bba998..a17fba8b 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -202,6 +202,7 @@
"Copy system information": "Copy system information",
"Could not import {0}: {1}": "Could not import {0}: {1}",
"Could not read {0}": "Could not read {0}",
+ "Could not render the sound: {0}": "Could not render the sound: {0}",
"Could not save: {0}": "Could not save: {0}",
"Could not show the file: {0}": "Could not show the file: {0}",
"Could not show the log: {0}": "Could not show the log: {0}",
@@ -574,6 +575,7 @@
"Nothing found to keep here, so the picture shows as shot. Try another subject, or custom removal.": "Nothing found to keep here, so the picture shows as shot. Try another subject, or custom removal.",
"Nothing of that kind in this project.": "Nothing of that kind in this project.",
"Nothing read aloud yet. Text to speech puts its voice here.": "Nothing read aloud yet. Text to speech puts its voice here.",
+ "Nothing rendered yet. Right-click a clip on the timeline and render its sound to put it here.": "Nothing rendered yet. Right-click a clip on the timeline and render its sound to put it here.",
"Nothing starred yet — hover a tile and press its star.": "Nothing starred yet — hover a tile and press its star.",
"Nothing to caption yet": "Nothing to caption yet",
"Nothing to export": "Nothing to export",
@@ -644,6 +646,8 @@
"Preview video only": "Preview video only",
"Previous frame": "Previous frame",
"Prism Dispersion": "Prism Dispersion",
+ "Processed": "Processed",
+ "processed": "processed",
"Processor": "Processor",
"PROJECT": "PROJECT",
"Project": "Project",
@@ -688,7 +692,9 @@
"Remove lane": "Remove lane",
"Remove panel": "Remove panel",
"Remove {0}": "Remove {0}",
+ "Render the sound as a file": "Render the sound as a file",
"Renderer": "Renderer",
+ "Rendering the sound…": "Rendering the sound…",
"Rendering video": "Rendering video",
"Resolution": "Resolution",
"Retro": "Retro",
@@ -800,6 +806,7 @@
"Sort: Name": "Sort: Name",
"Sort: Type": "Sort: Type",
"Sound": "Sound",
+ "Sound rendered to Generated › Processed": "Sound rendered to Generated › Processed",
"Source": "Source",
"Space": "Space",
"Spanish": "Spanish",
@@ -889,6 +896,7 @@
"There is nothing on the timeline to export": "There is nothing on the timeline to export",
"These settings apply to the whole edit and cannot be changed later.": "These settings apply to the whole edit and cannot be changed later.",
"This clip has no file to transcribe": "This clip has no file to transcribe",
+ "This clip has no sound to render": "This clip has no sound to render",
"This file has no picture to enhance": "This file has no picture to enhance",
"This model reads only with its own speakers": "This model reads only with its own speakers",
"Threshold": "Threshold",
diff --git a/src/crates/concat/src/panes/media_bin.rs b/src/crates/concat/src/panes/media_bin.rs
index 3a5b463f..518fd1c2 100644
--- a/src/crates/concat/src/panes/media_bin.rs
+++ b/src/crates/concat/src/panes/media_bin.rs
@@ -228,6 +228,7 @@ impl MediaBin {
MediaFilter::Audio => imported && item.kind == model::MediaKind::Audio,
MediaFilter::Images => imported && item.kind == model::MediaKind::Image,
MediaFilter::Speech => item.origin == Some(MediaOrigin::Speech),
+ MediaFilter::Processed => item.origin == Some(MediaOrigin::Processed),
}
}
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index f5285bef..acc97308 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -4525,6 +4525,91 @@ impl Studio {
/// Enhances the media of clip `id`: starts the job, unless one is
/// running, and says so.
+ /// Writes one clip's sound as it plays - trimmed, at its speed, with its
+ /// level, fades and effects baked in - to a WAV in the project's audio
+ /// folder, and puts the file in the bin under Generated › Processed. A
+ /// copy, not a replacement: the clip keeps its media and its settings,
+ /// and the file is independent of both, so it can be cut, moved and
+ /// exported like any import.
+ ///
+ /// The export's own audio path does the work, on the clip alone: the
+ /// project is flattened with just this clip on its timeline, the one
+ /// export clip that comes out is moved to the origin, and the mixer
+ /// writes it the way it writes an export's soundtrack.
+ pub fn render_clip_sound(&mut self, id: &str) {
+ let Some(clip) = self.clip(id).cloned() else {
+ return;
+ };
+ if !self.clip_has_sound(&clip) {
+ self.notify(&t("This clip has no sound to render"), true);
+ return;
+ }
+ let Some(project_dir) = self
+ .session
+ .as_ref()
+ .map(|session| std::path::PathBuf::from(session.path()))
+ else {
+ return;
+ };
+ let mut alone = self.project().clone();
+ alone.active_mut().clips.retain(|held| held.id == clip.id);
+ let Some(mut piece) =
+ concat_export::flatten::flatten_timeline_in(&alone, None, Some(&project_dir))
+ .into_iter()
+ .next()
+ else {
+ self.notify(&t("This clip has no sound to render"), true);
+ return;
+ };
+ piece.start = 0.0;
+ piece.muted = false;
+ let duration = piece.duration;
+ let pieces = concat_export::audio_pieces(&piece);
+
+ let out_dir = project_dir.join("audio");
+ let stamp = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map(|elapsed| elapsed.as_millis())
+ .unwrap_or(0);
+ let slug: String = clip
+ .name
+ .chars()
+ .map(|c| if c.is_alphanumeric() { c } else { '-' })
+ .take(40)
+ .collect();
+ let file = out_dir.join(format!("processed-{slug}-{stamp}.wav"));
+ let name = format!("{} · {}", clip.name, t("processed"));
+ log::info!(
+ "render: {} ({duration:.2}s, {} piece(s)) to {}",
+ clip.name,
+ pieces.len(),
+ file.display()
+ );
+ self.notify(&t("Rendering the sound…"), false);
+ spawn(
+ move || -> Result<concat_host::media::MediaSummary, String> {
+ std::fs::create_dir_all(&out_dir)
+ .map_err(|error| format!("could not create {}: {error}", out_dir.display()))?;
+ concat_media::audio::mix_to_file(&pieces, duration, &file)
+ .map_err(|error| error.to_string())?;
+ concat_host::media::probe(&file.to_string_lossy())
+ },
+ move |studio, _, _, result| match result {
+ Ok(summary) => {
+ let mut item = summary.to_new_media();
+ item.name = name;
+ item.origin = Some(model::MediaOrigin::Processed);
+ studio.apply(Command::AddMedia { item });
+ studio.notify(&t("Sound rendered to Generated › Processed"), false);
+ }
+ Err(error) => {
+ log::warn!("render: {error}");
+ studio.notify(&tf("Could not render the sound: {0}", &[&error]), true);
+ }
+ },
+ );
+ }
+
pub fn enhance_clip(&mut self, id: &str) {
if !self.enhance_jobs.is_empty() || self.host.enhancers.is_busy() {
self.notify(&t("Enhance is already at work; one clip at a time"), true);
@@ -6464,6 +6549,12 @@ impl Studio {
.filter(|item| item.origin == Some(model::MediaOrigin::Speech))
.count() as i32,
);
+ editor.set_media_count_processed(
+ items
+ .iter()
+ .filter(|item| item.origin == Some(model::MediaOrigin::Processed))
+ .count() as i32,
+ );
editor.set_media_selected_count(self.media.selected.len() as i32);
editor.set_importing(false);
@@ -6668,6 +6759,20 @@ impl Studio {
));
rows.push(rule());
}
+ // The clip's sound, written out as it plays, as a file of its own
+ // in the bin. For anything with sound in it; a clip whose track is
+ // muted still renders, since the file is the clip's and not the
+ // mix's.
+ if clip.kind == model::ClipKind::Audio || clip.kind == model::ClipKind::Video {
+ rows.push(action(
+ "render-sound",
+ t("Render the sound as a file"),
+ Glyph::Waveform,
+ "",
+ self.clip_has_sound(clip),
+ ));
+ rows.push(rule());
+ }
let audible = clip.kind != model::ClipKind::Image;
rows.push(check(
"mute",
@@ -7206,6 +7311,7 @@ impl Studio {
}
"freeze" => self.freeze_at_playhead(),
"enhance" => self.enhance_clip(id),
+ "render-sound" => self.render_clip_sound(id),
"detach" => {
self.apply(Command::DetachAudio {
clip_id: id.to_owned(),
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index 38baf8ee..7e2702c2 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -71,6 +71,7 @@ export global Editor {
in-out property <int> media-count-audio;
in-out property <int> media-count-images;
in-out property <int> media-count-speech;
+ in-out property <int> media-count-processed;
in-out property <int> media-selected-count;
in-out property <bool> importing;
diff --git a/src/crates/concat/ui/workspace/media-pane.slint b/src/crates/concat/ui/workspace/media-pane.slint
index 2c2d066e..2f5a3a93 100644
--- a/src/crates/concat/ui/workspace/media-pane.slint
+++ b/src/crates/concat/ui/workspace/media-pane.slint
@@ -24,7 +24,7 @@ export enum MediaKind { video, audio, image }
/// the row that is highlighted when every import is on, which is why it is a
/// value here and not the absence of one. `speech` is the Generated group's
/// shelf: what the editor read aloud, which the Media rows leave out.
-export enum MediaFilter { all, video, audio, images, speech }
+export enum MediaFilter { all, video, audio, images, speech, processed }
/// One look a title can be given, as the Text page's Presets shelf shows
/// it: enough of the style to draw the name in it. Published by Rust from
@@ -1411,6 +1411,7 @@ export component MediaPane inherits Rectangle {
in property <int> count-images;
/// What the editor made, by origin; not in `count-all`.
in property <int> count-speech;
+ in property <int> count-processed;
/// how many of the whole bin are selected, not how many of `items` are
in property <int> selected-count;
in property <bool> importing;
@@ -1886,6 +1887,16 @@ export component MediaPane inherits Rectangle {
current: root.filter == MediaFilter.speech;
clicked => { root.narrow(MediaFilter.speech); }
}
+ // A clip's sound written out as it played, from
+ // the clip's own menu: a file of its own, apart
+ // from the import it was cut from.
+ if root.generated-open: CategoryRow {
+ height: 24px;
+ label: I18n.t("Processed");
+ count: root.count-processed;
+ current: root.filter == MediaFilter.processed;
+ clicked => { root.narrow(MediaFilter.processed); }
+ }
}
if root.tab == 1: VerticalLayout {
@@ -2109,6 +2120,8 @@ export component MediaPane inherits Rectangle {
glyph: Glyph.import;
text: root.filter == MediaFilter.speech
? I18n.t("Nothing read aloud yet. Text to speech puts its voice here.")
+ : root.filter == MediaFilter.processed
+ ? I18n.t("Nothing rendered yet. Right-click a clip on the timeline and render its sound to put it here.")
: root.count-all > 0
? I18n.t("Nothing of that kind in this project.")
: "Drop video and audio files anywhere in the window to import them.";
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index 702871d1..1470678d 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -98,6 +98,7 @@ export component Seat inherits Rectangle {
count-audio: Editor.media-count-audio;
count-images: Editor.media-count-images;
count-speech: Editor.media-count-speech;
+ count-processed: Editor.media-count-processed;
selected-count: Editor.media-selected-count;
importing: Editor.importing;