Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: include enabled captions in every video export

Richie McIlroyd3f3337c33e9
diff --git a/apps/desktop-gpui/README.md b/apps/desktop-gpui/README.md
index 9d01d6a96..00cbc2a14 100644
--- a/apps/desktop-gpui/README.md
+++ b/apps/desktop-gpui/README.md
@@ -1908,7 +1908,6 @@ steps and side effects are the call site's.
| | Uppercase / Active Word Highlight (+ Highlight Color, Style) | toggles, then a hex field and a select | — | `captions.settings.{uppercase,activeWordHighlight,highlightColor,highlightStyle}` |
| | Background Settings → Color / Opacity | hex field + swatch, slider | 0–100 / 1 `%` | `captions.settings.{backgroundColor,backgroundOpacity}` |
| | Position / Animation / Font Weight | three selects | — | `captions.settings.{position,fontWeight}`, `{fade,linger,wordTransition}Duration` |
-| | Export Options → Export with Subtitles | toggle | — | `captions.settings.exportWithSubtitles` |
Two things in these tabs are honest dead ends rather than key paths, and both
say so in the UI:
diff --git a/apps/desktop-gpui/src/editor_tabs.rs b/apps/desktop-gpui/src/editor_tabs.rs
index 9afeb1e5e..a79364748 100644
--- a/apps/desktop-gpui/src/editor_tabs.rs
+++ b/apps/desktop-gpui/src/editor_tabs.rs
@@ -2887,22 +2887,6 @@ impl EditorWindow {
weight_label,
cx,
)),
- )
- .child(
- ui::Field::section(&theme, "Export Options").child(
- ui::Subfield::plain(&theme, "Export with Subtitles").child(
- ui::Toggle::plain(&theme, "caption-export", settings.export_with_subtitles)
- .on_click(cx.listener(|this, _, window, cx| {
- let next = !caption_settings(&this.project).export_with_subtitles;
- this.set_caption_setting(
- "caption-export",
- window,
- cx,
- move |settings| settings.export_with_subtitles = next,
- );
- })),
- ),
- ),
);
// An extra flex ancestor here repeats intrinsic layout while scrolling.
diff --git a/apps/desktop/src-tauri/src/export.rs b/apps/desktop/src-tauri/src/export.rs
index f5b87f89c..57eda8a5c 100644
--- a/apps/desktop/src-tauri/src/export.rs
+++ b/apps/desktop/src-tauri/src/export.rs
@@ -1040,7 +1040,7 @@ fn export_project_config(
if cursor_only {
make_cursor_only_project(project_config)
} else {
- cap_export::prepare_project_for_export(project_config)
+ project_config
}
}
@@ -2249,7 +2249,7 @@ mod tests {
.await
.unwrap();
let settings = preview.captions.unwrap().settings;
- assert_eq!(settings.enabled, export_with_subtitles);
+ assert!(settings.enabled);
assert_eq!(settings.export_with_subtitles, export_with_subtitles);
assert!(
!receiver
@@ -2347,10 +2347,7 @@ mod tests {
if cursor_only {
assert!(preview.captions.is_none());
} else {
- assert_eq!(
- preview.captions.unwrap().settings.enabled,
- enabled && export
- );
+ assert_eq!(preview.captions.unwrap().settings.enabled, enabled);
}
assert_eq!(serde_json::to_value(editor).unwrap(), original);
}
diff --git a/apps/desktop/src/routes/editor/CaptionsTab.tsx b/apps/desktop/src/routes/editor/CaptionsTab.tsx
index ea3d58c0e..ccdb04a06 100644
--- a/apps/desktop/src/routes/editor/CaptionsTab.tsx
+++ b/apps/desktop/src/routes/editor/CaptionsTab.tsx
@@ -1448,20 +1448,6 @@ export function CaptionsTab(props: {
</Field>
</div>
</Section>
-
- <div class="w-full border-t border-ed-line" />
-
- <Section name="Export options">
- <Field name="Export with Subtitles" inline>
- <Toggle
- checked={getSetting("exportWithSubtitles")}
- onChange={(checked) =>
- updateCaptionSetting("exportWithSubtitles", checked)
- }
- disabled={!hasCaptions()}
- />
- </Field>
- </Section>
</div>
<Show
diff --git a/apps/web/__tests__/unit/agent-docs.test.ts b/apps/web/__tests__/unit/agent-docs.test.ts
index 37cd24e8c..38d5f24f4 100644
--- a/apps/web/__tests__/unit/agent-docs.test.ts
+++ b/apps/web/__tests__/unit/agent-docs.test.ts
@@ -160,7 +160,7 @@ describe("Cap for Agents docs", () => {
"Highlight",
"They do not automatically follow",
"multiple text lanes",
- "Export with Subtitles",
+ "Enabled captions are automatically rendered",
"WebVTT (VTT)",
"Generate and edit captions",
"Show recorded keyboard input",
diff --git a/apps/web/content/docs/recording/studio-mode.mdx b/apps/web/content/docs/recording/studio-mode.mdx
index fbf292140..9e14a4ddf 100644
--- a/apps/web/content/docs/recording/studio-mode.mdx
+++ b/apps/web/content/docs/recording/studio-mode.mdx
@@ -103,7 +103,7 @@ The **Captions** tool is a beta, local transcription workflow for projects with
Caption presentation includes style presets plus controls for font, size, weight, uppercase text, foreground and background colors, background opacity, position, active-word highlighting, highlight color, animation, and fade duration.
-Turn on **Export with Subtitles** to render captions into the video. The Transcript view can also save the edited timeline captions as SRT or WebVTT (VTT) files.
+Enabled captions are automatically rendered into exported videos. Deleting words in the Captions panel edits the caption text; use **Cut video** to remove the corresponding footage. The Transcript view can also save the edited timeline captions as SRT or WebVTT (VTT) files.
## Show recorded keyboard input
diff --git a/crates/export/src/estimates.rs b/crates/export/src/estimates.rs
index 5fad082b1..99bd390dd 100644
--- a/crates/export/src/estimates.rs
+++ b/crates/export/src/estimates.rs
@@ -16,8 +16,7 @@ use serde::Serialize;
use specta::Type;
use crate::{
- ExporterBase, make_cursor_only_project, prepare_project_for_export, settings::ExportSettings,
- synthesize_default_timeline,
+ ExporterBase, make_cursor_only_project, settings::ExportSettings, synthesize_default_timeline,
};
#[derive(Clone, Debug, Serialize, Type)]
@@ -142,7 +141,7 @@ pub async fn estimate_export(
if resolution.x == 0 || resolution.y == 0 {
return Err("Invalid export resolution".into());
}
- let mut project = prepare_project_for_export(project);
+ let mut project = project;
if settings.cursor_only() {
project = make_cursor_only_project(project);
}
diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs
index 9ea2e3aba..9a80fb484 100644
--- a/crates/export/src/lib.rs
+++ b/crates/export/src/lib.rs
@@ -104,7 +104,7 @@ impl ExporterBuilder {
ProjectConfiguration::load(&self.project_path)
.map_err(|error| ExporterBuildError::ConfigLoad(error.into()))?
};
- Ok(prepare_project_for_export(project_config))
+ Ok(project_config)
}
async fn build_inner(
@@ -286,15 +286,6 @@ pub fn synthesize_default_timeline(
}
}
-pub fn prepare_project_for_export(
- mut project_config: ProjectConfiguration,
-) -> ProjectConfiguration {
- if let Some(captions) = &mut project_config.captions {
- captions.settings.enabled &= captions.settings.export_with_subtitles;
- }
- project_config
-}
-
pub fn make_cursor_only_project(mut project_config: ProjectConfiguration) -> ProjectConfiguration {
fn clear_background_pixels(background: &mut cap_project::BackgroundConfiguration) {
background.source = BackgroundSource::Color {
@@ -656,6 +647,8 @@ mod subtitle_export_tests {
fn project(enabled: bool, export: bool) -> ProjectConfiguration {
serde_json::from_value(serde_json::json!({
+ "textSizeVersion": 1,
+ "textAnimVersion": 1,
"captions": {
"segments": [{"id": "source", "start": 0.0, "end": 2.0, "text": "Keep this caption"}],
"sourceTimed": true,
@@ -671,22 +664,35 @@ mod subtitle_export_tests {
}
#[test]
- fn subtitle_export_requires_both_switches_and_preserves_editor_config() {
+ fn subtitle_export_builder_preserves_caption_visibility_for_disk_and_explicit_configs() {
+ let temp = tempfile::tempdir().unwrap();
+ let path = temp.path().join("project-config.json");
for enabled in [false, true] {
for export in [false, true] {
let editor = project(enabled, export);
let original = serde_json::to_value(&editor).unwrap();
- let mut expected = original.clone();
- expected["captions"]["settings"]["enabled"] = (enabled && export).into();
- let output = prepare_project_for_export(editor.clone());
- assert_eq!(serde_json::to_value(output).unwrap(), expected);
- assert_eq!(serde_json::to_value(editor).unwrap(), original);
+ std::fs::write(&path, serde_json::to_vec(&editor).unwrap()).unwrap();
+ let mut disk = ExporterBase::builder(temp.path().to_path_buf());
+ let mut explicit =
+ ExporterBase::builder(temp.path().to_path_buf()).with_config(editor);
+ for output in [
+ disk.load_project_config().unwrap(),
+ explicit.load_project_config().unwrap(),
+ ] {
+ assert_eq!(output.captions.as_ref().unwrap().settings.enabled, enabled);
+ assert_eq!(serde_json::to_value(output).unwrap(), original);
+ }
+ let persisted: ProjectConfiguration =
+ serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
+ assert_eq!(serde_json::to_value(persisted).unwrap(), original);
}
}
}
#[test]
- fn subtitle_export_preserves_legacy_default_off() {
+ fn subtitle_export_includes_legacy_captions_without_an_export_setting() {
+ let temp = tempfile::tempdir().unwrap();
+ let path = temp.path().join("project-config.json");
let mut value = serde_json::to_value(project(true, true)).unwrap();
assert!(
value["captions"]["settings"]
@@ -695,63 +701,27 @@ mod subtitle_export_tests {
.remove("exportWithSubtitles")
.is_some()
);
- let editor: ProjectConfiguration = serde_json::from_value(value).unwrap();
- assert!(editor.captions.as_ref().unwrap().settings.enabled);
- assert!(
- !editor
- .captions
- .as_ref()
- .unwrap()
- .settings
- .export_with_subtitles
- );
- let output = prepare_project_for_export(editor);
- assert!(!output.captions.unwrap().settings.enabled);
- }
-
- #[test]
- fn subtitle_export_transform_is_idempotent_and_keeps_missing_captions_missing() {
- let empty = ProjectConfiguration::default();
- assert_eq!(
- serde_json::to_value(prepare_project_for_export(empty.clone())).unwrap(),
- serde_json::to_value(empty).unwrap()
- );
- for export in [false, true] {
- let once = prepare_project_for_export(project(true, export));
- let twice = prepare_project_for_export(once.clone());
- assert_eq!(
- serde_json::to_value(once).unwrap(),
- serde_json::to_value(twice).unwrap()
- );
- }
+ std::fs::write(&path, serde_json::to_vec(&value).unwrap()).unwrap();
+ let mut builder = ExporterBase::builder(temp.path().to_path_buf());
+ let output = builder.load_project_config().unwrap();
+ let settings = output.captions.unwrap().settings;
+ assert!(settings.enabled);
+ assert!(!settings.export_with_subtitles);
}
#[test]
- fn subtitle_export_builder_applies_policy_to_disk_and_explicit_configs() {
- let temp = tempfile::tempdir().unwrap();
- let path = temp.path().join("project-config.json");
- for export in [false, true] {
- let editor = project(true, export);
- std::fs::write(&path, serde_json::to_vec(&editor).unwrap()).unwrap();
- let mut disk = ExporterBase::builder(temp.path().to_path_buf());
- let mut explicit = ExporterBase::builder(temp.path().to_path_buf()).with_config(editor);
- for output in [
- disk.load_project_config().unwrap(),
- explicit.load_project_config().unwrap(),
- ] {
- assert_eq!(output.captions.unwrap().settings.enabled, export);
- }
- let persisted: ProjectConfiguration =
- serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
- assert!(persisted.captions.unwrap().settings.enabled);
- }
+ fn subtitle_export_keeps_missing_captions_missing() {
+ let mut builder = ExporterBase::builder(PathBuf::from("unused-project"))
+ .with_config(ProjectConfiguration::default());
+ assert!(builder.load_project_config().unwrap().captions.is_none());
}
#[test]
fn subtitle_export_never_reintroduces_cursor_only_captions() {
for export in [false, true] {
- let output =
- prepare_project_for_export(make_cursor_only_project(project(true, export)));
+ let mut builder = ExporterBase::builder(PathBuf::from("unused-project"))
+ .with_config(make_cursor_only_project(project(true, export)));
+ let output = builder.load_project_config().unwrap();
assert!(output.captions.is_none());
assert!(output.timeline.unwrap().caption_segments.is_empty());
}
diff --git a/crates/export/src/preview.rs b/crates/export/src/preview.rs
index 3257d07e7..45befeaa6 100644
--- a/crates/export/src/preview.rs
+++ b/crates/export/src/preview.rs
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
use crate::{
ExportError, ExporterBase, ExporterBuilder, make_cursor_only_project,
- prepare_project_for_export, synthesize_default_timeline,
+ synthesize_default_timeline,
};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
@@ -149,7 +149,7 @@ pub async fn render_preview_with_editor(
let studio_meta = recording_meta
.studio_meta()
.ok_or_else(|| ExportError::Other("Cannot preview non-studio recordings".to_string()))?;
- let mut project_config = prepare_project_for_export(project_config);
+ let mut project_config = project_config;
if settings.cursor_only {
project_config = make_cursor_only_project(project_config);
}
@@ -561,7 +561,7 @@ mod subtitle_preview_tests {
use super::*;
#[test]
- fn immediate_export_preview_uses_current_toggle_before_disk_save() {
+ fn immediate_export_preview_keeps_enabled_captions_regardless_of_legacy_export_toggle() {
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("project-config.json");
for export in [false, true] {
@@ -598,7 +598,7 @@ mod subtitle_preview_tests {
true,
);
let preview = builder.load_project_config().unwrap();
- assert_eq!(preview.captions.as_ref().unwrap().settings.enabled, export);
+ assert!(preview.captions.as_ref().unwrap().settings.enabled);
assert_eq!(
preview.captions.unwrap().settings.export_with_subtitles,
export
diff --git a/crates/render-farm/src/project.rs b/crates/render-farm/src/project.rs
index 61d6d1d66..f504a099d 100644
--- a/crates/render-farm/src/project.rs
+++ b/crates/render-farm/src/project.rs
@@ -21,8 +21,7 @@ pub struct LoadedProject {
impl LoadedProject {
pub fn load(path: &Path) -> Result<Self> {
- let config = ProjectConfiguration::load(path).context("project-config.json")?;
- let mut config = cap_export::prepare_project_for_export(config);
+ let mut config = ProjectConfiguration::load(path).context("project-config.json")?;
let recording_meta = RecordingMeta::load_for_project(path)
.map_err(|error| anyhow!("recording-meta.json: {error}"))?;
let studio_meta = recording_meta