Skip to content

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

refactor(ui): the export sheet is the first pane behind a message

Jareereb5aad307d79
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 9381ff36..f6e56ed6 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -42,6 +42,7 @@ mod platform;
/// the system's file picker. See `platform::pick_files_async`.
#[cfg(any(target_os = "android", target_os = "ios"))]
pub use platform::{FilePicker, install_file_picker};
+mod panes;
mod prefs;
mod presets;
mod studio;
@@ -49,6 +50,8 @@ mod sysinfo;
use dock::{Dock, SEAT_MIN_GRAB, SEAT_MIN_H, SEAT_MIN_W};
use host::{Host, Shell, on_ui};
+use panes::Msg;
+use panes::export::ExportMsg;
use studio::{Models, OUTPUTS, RESOLUTIONS, START_RATES, Studio};
use ui::*;
@@ -940,9 +943,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
// ── the dialogs ──
app.on_export_clicked(on_window!(|state| {
- state.export.open = true;
- state.export.phase = ExportPhase::Idle;
- state.export.message.clear();
+ state.handle(Msg::Export(ExportMsg::Open));
}));
app.on_open_settings(on_window!(|state| {
state.refresh_models();
@@ -961,50 +962,43 @@ pub fn run() -> Result<(), slint::PlatformError> {
}
});
app.on_export_closed(on_window!(|state| {
- state.export.open = false;
+ state.handle(Msg::Export(ExportMsg::Close));
}));
app.on_settings_closed(on_window!(|state| {
state.settings.open = false;
}));
app.on_export_name_edited(on_window!(|state, name: SharedString| {
- state.export.name = name.to_string();
+ state.handle(Msg::Export(ExportMsg::NameEdited(name.to_string())));
}));
app.on_export_resolution_changed(on_window!(|state, index: i32| {
- state.export.resolution = (index.max(0) as usize).min(3);
+ state.handle(Msg::Export(ExportMsg::ResolutionChanged(index)));
}));
app.on_export_rate_changed(on_window!(|state, index: i32| {
- state.export.rate = (index.max(0) as usize).min(2);
+ state.handle(Msg::Export(ExportMsg::RateChanged(index)));
}));
app.on_export_quality_changed(on_window!(|state, index: i32| {
- state.export.quality = (index.max(0) as usize).min(2);
+ state.handle(Msg::Export(ExportMsg::QualityChanged(index)));
}));
app.on_export_codec_changed(on_window!(|state, index: i32| {
- state.export.codec = (index.max(0) as usize).min(2);
+ state.handle(Msg::Export(ExportMsg::CodecChanged(index)));
}));
app.on_export_ten_bit_changed(on_window!(|state, on: bool| {
- state.export.ten_bit = on;
+ state.handle(Msg::Export(ExportMsg::TenBitChanged(on)));
}));
app.on_export_again(on_window!(|state| {
- state.export.phase = ExportPhase::Idle;
- state.export.progress = 0.0;
+ state.handle(Msg::Export(ExportMsg::Again));
}));
app.on_export_browse(on_window!(|state| {
- if let Some(folder) = platform::pick_folder(&i18n::t("Export to"), &state.export.folder) {
- state.export.folder = folder.to_string_lossy().into_owned();
- }
+ state.handle(Msg::Export(ExportMsg::Browse));
}));
app.on_export_reveal(on_window!(|state| {
- if !state.export.written.is_empty()
- && let Err(error) = platform::reveal(&state.export.written)
- {
- state.notify(&i18n::tf("Could not show the file: {0}", &[&error]), true);
- }
+ state.handle(Msg::Export(ExportMsg::Reveal));
}));
app.on_export_cancel(on_window!(|state| {
- state.export_cancel();
+ state.handle(Msg::Export(ExportMsg::Cancel));
}));
app.on_export_start(on_window!(|state| {
- state.export_start();
+ state.handle(Msg::Export(ExportMsg::Start));
}));
// ── settings ──
@@ -1176,11 +1170,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
on_ui(move |studio, _, _| studio.import(paths))
});
}
- "export" => {
- state.export.open = true;
- state.export.phase = ExportPhase::Idle;
- state.export.message.clear();
- }
+ "export" => state.handle(Msg::Export(ExportMsg::Open)),
"template" => state.save_template(),
"speech" => state.speech_open(),
"clear-cache" => state.clear_project_cache(),
diff --git a/src/crates/concat/src/panes/export.rs b/src/crates/concat/src/panes/export.rs
new file mode 100644
index 00000000..4a2a83bd
--- /dev/null
+++ b/src/crates/concat/src/panes/export.rs
@@ -0,0 +1,354 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The export sheet: the form, the running render, and the result.
+//!
+//! The first pane cut out of the window's controller, and the shape every
+//! later one follows. The pane owns its state; every way it can change -
+//! a field edited, a button pressed, a worker reporting - is one
+//! [`ExportMsg`]; [`ExportPane::update`] is the only code that changes the
+//! state; and [`ExportPane::data`] is the one place its Slint rows are
+//! built. The controller it needs for context - the session, the output
+//! size, the job slots - is handed to `update` as the studio, which the
+//! pane reads and asks things of but never reaches into for its own
+//! fields.
+
+use concat_host::export::{self, ExportSpec};
+
+use crate::format::{bytes, eta};
+use crate::host::{on_ui, spawn};
+use crate::i18n::{self, t, tf};
+use crate::panes::Msg;
+use crate::platform;
+use crate::studio::{
+ AUDIO_BPS, EXPORT_CRF, EXPORT_RATES, EXPORT_SHORT_SIDES, EXPORT_TIERS, Studio, home_folder,
+};
+use crate::ui::{ExportData, ExportPhase};
+
+/// Everything that can happen to the export sheet.
+#[derive(Clone, Debug)]
+pub enum ExportMsg {
+ /// The sheet is asked for: the menu, the tray button or ⌘E.
+ Open,
+ /// The sheet is dismissed.
+ Close,
+ NameEdited(String),
+ ResolutionChanged(i32),
+ RateChanged(i32),
+ QualityChanged(i32),
+ CodecChanged(i32),
+ TenBitChanged(bool),
+ /// Back to the form after a finished or failed render.
+ Again,
+ /// Pick the destination folder.
+ Browse,
+ /// Show the finished file in the file manager.
+ Reveal,
+ Start,
+ Cancel,
+ /// The render's worker reporting where it is.
+ Progress {
+ /// Of the whole, `0..=1`.
+ fraction: f32,
+ /// What it is doing, in the person's language.
+ stage: String,
+ },
+ /// The render's worker is done: the file written, or why not.
+ Finished(Result<String, String>),
+}
+
+/// The export sheet's state.
+pub struct ExportPane {
+ pub open: bool,
+ pub name: String,
+ pub folder: String,
+ pub resolution: usize,
+ pub rate: usize,
+ pub quality: usize,
+ /// Index into `VideoCodec::ALL`.
+ pub codec: usize,
+ pub ten_bit: bool,
+ pub phase: ExportPhase,
+ pub progress: f32,
+ pub stage: String,
+ pub message: String,
+ /// Where the finished file is, for Reveal.
+ pub written: String,
+ /// When the render started, for a real ETA.
+ started_at: Option<std::time::Instant>,
+}
+
+impl Default for ExportPane {
+ fn default() -> Self {
+ Self {
+ open: false,
+ name: "Untitled".into(),
+ folder: home_folder("Movies"),
+ resolution: 2,
+ rate: 1,
+ quality: 1,
+ codec: 0,
+ ten_bit: false,
+ phase: ExportPhase::Idle,
+ progress: 0.0,
+ stage: String::new(),
+ message: String::new(),
+ written: String::new(),
+ started_at: None,
+ }
+ }
+}
+
+impl ExportPane {
+ /// Applies one message. The studio is the rest of the window, for
+ /// what the sheet needs to know and to start; the pane's own state is
+ /// `self`, and while this runs the studio's copy of it is a blank the
+ /// pane must not read.
+ pub fn update(&mut self, msg: ExportMsg, studio: &mut Studio) {
+ match msg {
+ ExportMsg::Open => {
+ self.open = true;
+ self.phase = ExportPhase::Idle;
+ self.message.clear();
+ }
+ ExportMsg::Close => self.open = false,
+ ExportMsg::NameEdited(name) => self.name = name,
+ ExportMsg::ResolutionChanged(index) => {
+ self.resolution = (index.max(0) as usize).min(3);
+ }
+ ExportMsg::RateChanged(index) => self.rate = (index.max(0) as usize).min(2),
+ ExportMsg::QualityChanged(index) => self.quality = (index.max(0) as usize).min(2),
+ ExportMsg::CodecChanged(index) => self.codec = (index.max(0) as usize).min(2),
+ ExportMsg::TenBitChanged(on) => self.ten_bit = on,
+ ExportMsg::Again => {
+ self.phase = ExportPhase::Idle;
+ self.progress = 0.0;
+ }
+ ExportMsg::Browse => {
+ if let Some(folder) = platform::pick_folder(&i18n::t("Export to"), &self.folder) {
+ self.folder = folder.to_string_lossy().into_owned();
+ }
+ }
+ ExportMsg::Reveal => {
+ if !self.written.is_empty()
+ && let Err(error) = platform::reveal(&self.written)
+ {
+ studio.notify(&i18n::tf("Could not show the file: {0}", &[&error]), true);
+ }
+ }
+ ExportMsg::Start => self.start(studio),
+ ExportMsg::Cancel => {
+ studio.host.exporter.cancel();
+ self.phase = ExportPhase::Idle;
+ self.progress = 0.0;
+ }
+ ExportMsg::Progress { fraction, stage } => {
+ if self.phase == ExportPhase::Running {
+ self.progress = fraction.clamp(0.0, 1.0);
+ self.stage = stage;
+ }
+ }
+ ExportMsg::Finished(Ok(written)) => {
+ self.phase = ExportPhase::Done;
+ self.progress = 1.0;
+ self.written = written;
+ studio.notify(&t("Export finished"), false);
+ }
+ ExportMsg::Finished(Err(error)) => {
+ if self.phase == ExportPhase::Idle {
+ // Cancelled: the sheet already went back to idle.
+ return;
+ }
+ self.phase = ExportPhase::Failed;
+ self.message = error.clone();
+ studio.notify(&tf("Export failed: {0}", &[&error]), true);
+ }
+ }
+ }
+
+ /// The frame the export renders at: the sheet's short side, scaled
+ /// along the project's aspect and rounded to even dimensions, which is
+ /// what the encoder's chroma subsampling needs.
+ pub fn size(&self, studio: &Studio) -> (u32, u32) {
+ let short = EXPORT_SHORT_SIDES[self.resolution.min(EXPORT_SHORT_SIDES.len() - 1)];
+ let (project_w, project_h) = studio.output_size();
+ let (project_w, project_h) = (project_w.max(1) as f64, project_h.max(1) as f64);
+ let even = |side: f64| ((side / 2.0).round() as u32 * 2).max(2);
+ if project_w >= project_h {
+ (even(short as f64 * project_w / project_h), short)
+ } else {
+ (short, even(short as f64 * project_h / project_w))
+ }
+ }
+
+ /// A rough size of the file at one quality tier, in bytes.
+ pub fn size_bytes(&self, studio: &Studio, tier: usize) -> f32 {
+ let (width, height) = self.size(studio);
+ let (num, den) = EXPORT_RATES[self.rate.min(2)];
+ let rate = num as f32 / den as f32;
+ let pixels = (width as f32 * height as f32) / (1920.0 * 1080.0);
+ let video = EXPORT_TIERS[tier.min(2)]
+ * 1_000_000.0
+ * pixels
+ * (rate / 30.0)
+ * self.codec().size_factor()
+ * if self.ten_bit { 1.05 } else { 1.0 };
+ (video + AUDIO_BPS) * studio.duration().max(1.0) / 8.0
+ }
+
+ /// The codec the sheet has chosen.
+ pub fn codec(&self) -> concat_media::VideoCodec {
+ concat_media::VideoCodec::ALL[self.codec.min(concat_media::VideoCodec::ALL.len() - 1)]
+ }
+
+ /// Starts the render on a worker. Its reports come back as messages.
+ fn start(&mut self, studio: &mut Studio) {
+ let Some(session) = studio.session.as_ref() else {
+ return;
+ };
+ if studio.timeline().clips.is_empty() {
+ self.phase = ExportPhase::Failed;
+ self.message = t("There is nothing on the timeline to export");
+ return;
+ }
+ let job = match studio.host.exporter.begin() {
+ Ok(job) => job,
+ Err(error) => {
+ self.phase = ExportPhase::Failed;
+ self.message = error;
+ return;
+ }
+ };
+ let output = format!(
+ "{}/{}.mp4",
+ self.folder.trim_end_matches('/'),
+ self.name.trim()
+ );
+ let spec = ExportSpec {
+ output: output.clone(),
+ crf: EXPORT_CRF[self.quality.min(2)],
+ preset: "veryfast".into(),
+ codec: self.codec(),
+ ten_bit: self.ten_bit,
+ };
+ let (frame_w, frame_h) = studio.output_size();
+ let titles = studio
+ .host
+ .titles
+ .clips(session.project(), frame_w, frame_h)
+ .into_iter()
+ .map(|title| title.clip)
+ .collect();
+ let mut request = export::request(session, &spec, titles);
+ let (width, height) = self.size(studio);
+ let (num, den) = EXPORT_RATES[self.rate.min(2)];
+ request.width = width;
+ request.height = height;
+ request.rate_num = num;
+ request.rate_den = den;
+
+ studio.pause();
+ self.phase = ExportPhase::Running;
+ self.progress = 0.0;
+ self.stage = t("Rendering video");
+ self.message.clear();
+ self.written.clear();
+ self.started_at = Some(std::time::Instant::now());
+
+ spawn(
+ move || {
+ let job = job;
+ export::run(&request, job.cancel_flag(), |progress| {
+ let fraction = if progress.total > 0 {
+ progress.frame as f32 / progress.total as f32
+ } else {
+ 0.0
+ };
+ let stage = match progress.stage {
+ "rendering" => t("Rendering video"),
+ "mixing audio" => t("Mixing audio"),
+ "muxing" => t("Finalising file"),
+ other => other.to_owned(),
+ };
+ on_ui(move |studio, _, _| {
+ studio.handle(Msg::Export(ExportMsg::Progress { fraction, stage }));
+ });
+ })
+ },
+ |studio, _, _, result| studio.handle(Msg::Export(ExportMsg::Finished(result))),
+ );
+ }
+
+ /// The sheet as Slint shows it.
+ pub fn data(&self, studio: &Studio) -> ExportData {
+ let (width, height) = self.size(studio);
+ let (num, den) = EXPORT_RATES[self.rate.min(2)];
+ let rate = num as f32 / den as f32;
+ let clips = studio.timeline().clips.len();
+ let titles = studio
+ .timeline()
+ .clips
+ .iter()
+ .filter(|clip| clip.kind == concat_project::model::ClipKind::Text)
+ .count();
+ ExportData {
+ open: self.open,
+ name: self.name.as_str().into(),
+ path: format!("{}/{}.mp4", self.folder.trim_end_matches('/'), self.name).into(),
+ format: format!("{width} × {height} · {rate:.2} fps").into(),
+ duration: {
+ let whole = studio.duration().max(0.0) as i32;
+ format!("{}:{:02}", whole / 60, whole % 60).into()
+ },
+ contents: if titles > 0 {
+ format!("{clips} clips · {titles} titles")
+ } else {
+ format!("{clips} clips")
+ }
+ .into(),
+ resolution: self.resolution as i32,
+ rate: self.rate as i32,
+ quality: self.quality as i32,
+ codec: self.codec as i32,
+ ten_bit: self.ten_bit,
+ encoding: {
+ // "HEVC 10-bit · hardware": the standard, the depth when it
+ // is the deeper one, and whether the platform's own encoder
+ // will be doing it.
+ let codec = self.codec();
+ let mut words = vec![codec.label().to_owned()];
+ if self.ten_bit {
+ words.push("10-bit".to_owned());
+ }
+ if codec
+ .encoders(true)
+ .first()
+ .is_some_and(|name| name.ends_with("_videotoolbox"))
+ {
+ words.push(format!("· {}", t("hardware")));
+ }
+ words.join(" ")
+ }
+ .into(),
+ size_high: bytes(self.size_bytes(studio, 0)).into(),
+ size_balanced: bytes(self.size_bytes(studio, 1)).into(),
+ size_small: bytes(self.size_bytes(studio, 2)).into(),
+ phase: self.phase,
+ progress: self.progress,
+ stage: self.stage.as_str().into(),
+ eta: if self.phase == ExportPhase::Running && self.progress > 0.02 {
+ self.started_at
+ .map(|started| {
+ let elapsed = started.elapsed().as_secs_f32();
+ eta(elapsed / self.progress * (1.0 - self.progress)).into()
+ })
+ .unwrap_or_default()
+ } else {
+ slint::SharedString::new()
+ },
+ message: self.message.as_str().into(),
+ done_size: bytes(self.size_bytes(studio, self.quality)).into(),
+ empty: clips == 0,
+ }
+ }
+}
diff --git a/src/crates/concat/src/panes/mod.rs b/src/crates/concat/src/panes/mod.rs
new file mode 100644
index 00000000..abe48737
--- /dev/null
+++ b/src/crates/concat/src/panes/mod.rs
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The window, one pane at a time.
+//!
+//! Each pane owns its state and is changed only by its own messages: a
+//! Slint callback and a worker's report are the same thing, one [`Msg`]
+//! posted to [`crate::studio::Studio::handle`], which routes it to the pane
+//! and publishes. A message that arrives after the project it concerns
+//! has closed is dropped there, in one place, rather than guarded against
+//! in every closure.
+//!
+//! The panes move here one at a time from the window's controller; the
+//! export sheet is the first, and the shape the rest follow.
+
+pub mod export;
+
+/// One thing that happened, to one pane.
+#[derive(Clone, Debug)]
+pub enum Msg {
+ /// To the export sheet.
+ Export(export::ExportMsg),
+}
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 5cea096b..71873cb7 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -31,7 +31,6 @@ use std::sync::Arc;
use concat_effects::Catalogue;
use concat_effects::manifest::Kind as PackageKind;
-use concat_host::export::{self, ExportSpec};
use concat_host::playback::ClipSpec;
use concat_host::preview::FrameSpec;
use concat_host::{
@@ -48,9 +47,7 @@ use slint::{Model, SharedString, VecModel};
use crate::dock::{
Dock, DockLayout, SEAT_GAP, default_dock, lay_out, nearest_row, row_at, row_top,
};
-use crate::format::{
- bytes, colour_of, eta, frames_timecode, hex_of, hex_with_alpha, wave_path, when_phrase,
-};
+use crate::format::{colour_of, frames_timecode, hex_of, hex_with_alpha, wave_path, when_phrase};
use crate::host::{
CachedStrip, Host, MediaArt, WindowArt, cached_media_art, cached_window_art, image_at,
image_of, media_art, on_ui, spawn, spawn_art, strip_window, window_art, window_span,
@@ -151,9 +148,9 @@ pub const EXPORT_RATES: [(i64, i64); 3] = [(24, 1), (30, 1), (60, 1)];
pub const COMPACT_WIDTH: f32 = 860.0;
/// Megabits per second at 1080p30 for each quality tier, for the size
/// estimate; and the CRF each tier renders at.
-const EXPORT_TIERS: [f32; 3] = [16.0, 8.0, 4.0];
-const EXPORT_CRF: [u8; 3] = [16, 20, 26];
-const AUDIO_BPS: f32 = 192_000.0;
+pub(crate) const EXPORT_TIERS: [f32; 3] = [16.0, 8.0, 4.0];
+pub(crate) const EXPORT_CRF: [u8; 3] = [16, 20, 26];
+pub(crate) const AUDIO_BPS: f32 = 192_000.0;
/// The frame sizes the launch screen offers, and what each label means.
pub const RESOLUTIONS: [(&str, u32, u32); 4] = [
@@ -261,51 +258,9 @@ const CAPTION_SIZES: [f64; 3] = [0.04, 0.05, 0.065];
/// A rough speaking rate, for the estimate under the script.
const CHARS_PER_SECOND: f32 = 14.0;
-/// The export sheet's state.
-pub struct ExportState {
- pub open: bool,
- pub name: String,
- pub folder: String,
- pub resolution: usize,
- pub rate: usize,
- pub quality: usize,
- /// Index into `VideoCodec::ALL`.
- pub codec: usize,
- pub ten_bit: bool,
- pub phase: ExportPhase,
- pub progress: f32,
- pub stage: String,
- pub message: String,
- /// Where the finished file is, for Reveal.
- pub written: String,
- /// When the render started, for a real ETA.
- started_at: Option<std::time::Instant>,
-}
-
-impl Default for ExportState {
- fn default() -> Self {
- Self {
- open: false,
- name: "Untitled".into(),
- folder: home_folder("Movies"),
- resolution: 2,
- rate: 1,
- quality: 1,
- codec: 0,
- ten_bit: false,
- phase: ExportPhase::Idle,
- progress: 0.0,
- stage: String::new(),
- message: String::new(),
- written: String::new(),
- started_at: None,
- }
- }
-}
-
/// `name` under the home directory, as a path string; empty when there is
/// no home to speak of, and the form then asks for a folder outright.
-fn home_folder(name: &str) -> String {
+pub(crate) fn home_folder(name: &str) -> String {
std::env::var("HOME")
.map(|home| format!("{home}/{name}"))
.unwrap_or_default()
@@ -756,7 +711,7 @@ pub struct Studio {
preview_failed: bool,
// ── the sheets and menus ──
- pub export: ExportState,
+ pub export: crate::panes::export::ExportPane,
pub settings: SettingsState,
pub relink: RelinkState,
pub transcribers: Vec<ModelState>,
@@ -1435,7 +1390,7 @@ impl Studio {
preview_busy: false,
preview_wanted: false,
preview_failed: false,
- export: ExportState::default(),
+ export: Default::default(),
settings: SettingsState::default(),
relink: RelinkState::default(),
transcribers: Vec::new(),
@@ -5210,146 +5165,18 @@ impl Studio {
}
}
- // ── export ──
-
- /// The frame the export renders at: the sheet's short side, scaled
- /// along the project's aspect and rounded to even dimensions, which is
- /// what the encoder's chroma subsampling needs.
- pub fn export_size(&self) -> (u32, u32) {
- let short = EXPORT_SHORT_SIDES[self.export.resolution.min(EXPORT_SHORT_SIDES.len() - 1)];
- let (project_w, project_h) = self.output_size();
- let (project_w, project_h) = (project_w.max(1) as f64, project_h.max(1) as f64);
- let even = |side: f64| ((side / 2.0).round() as u32 * 2).max(2);
- if project_w >= project_h {
- (even(short as f64 * project_w / project_h), short)
- } else {
- (short, even(short as f64 * project_h / project_w))
- }
- }
-
- pub fn export_size_bytes(&self, tier: usize) -> f32 {
- let (width, height) = self.export_size();
- let (num, den) = EXPORT_RATES[self.export.rate.min(2)];
- let rate = num as f32 / den as f32;
- let pixels = (width as f32 * height as f32) / (1920.0 * 1080.0);
- let video = EXPORT_TIERS[tier.min(2)]
- * 1_000_000.0
- * pixels
- * (rate / 30.0)
- * self.export_codec().size_factor()
- * if self.export.ten_bit { 1.05 } else { 1.0 };
- (video + AUDIO_BPS) * self.duration().max(1.0) / 8.0
- }
-
- /// The codec the sheet has chosen.
- pub fn export_codec(&self) -> concat_media::VideoCodec {
- concat_media::VideoCodec::ALL[self
- .export
- .codec
- .min(concat_media::VideoCodec::ALL.len() - 1)]
- }
-
- /// Starts the render on a worker, reporting into the sheet.
- pub fn export_start(&mut self) {
- let Some(session) = self.session.as_ref() else {
- return;
- };
- if self.timeline().clips.is_empty() {
- self.export.phase = ExportPhase::Failed;
- self.export.message = t("There is nothing on the timeline to export");
- return;
- }
- let job = match self.host.exporter.begin() {
- Ok(job) => job,
- Err(error) => {
- self.export.phase = ExportPhase::Failed;
- self.export.message = error;
- return;
+ /// Routes one message to its pane and applies it. The pane is taken out
+ /// of the studio for the duration, so its `update` can be handed the
+ /// rest of the window without borrowing itself twice; a pane never
+ /// reads its own slot on the studio.
+ pub fn handle(&mut self, msg: crate::panes::Msg) {
+ match msg {
+ crate::panes::Msg::Export(msg) => {
+ let mut pane = std::mem::take(&mut self.export);
+ pane.update(msg, self);
+ self.export = pane;
}
- };
- let output = format!(
- "{}/{}.mp4",
- self.export.folder.trim_end_matches('/'),
- self.export.name.trim()
- );
- let spec = ExportSpec {
- output: output.clone(),
- crf: EXPORT_CRF[self.export.quality.min(2)],
- preset: "veryfast".into(),
- codec: self.export_codec(),
- ten_bit: self.export.ten_bit,
- };
- let (frame_w, frame_h) = self.output_size();
- let titles = self
- .host
- .titles
- .clips(session.project(), frame_w, frame_h)
- .into_iter()
- .map(|title| title.clip)
- .collect();
- let mut request = export::request(session, &spec, titles);
- let (width, height) = self.export_size();
- let (num, den) = EXPORT_RATES[self.export.rate.min(2)];
- request.width = width;
- request.height = height;
- request.rate_num = num;
- request.rate_den = den;
-
- self.pause();
- self.export.phase = ExportPhase::Running;
- self.export.progress = 0.0;
- self.export.stage = t("Rendering video");
- self.export.message.clear();
- self.export.written.clear();
- self.export.started_at = Some(std::time::Instant::now());
-
- spawn(
- move || {
- let job = job;
- export::run(&request, job.cancel_flag(), |progress| {
- let fraction = if progress.total > 0 {
- progress.frame as f32 / progress.total as f32
- } else {
- 0.0
- };
- let stage = match progress.stage {
- "rendering" => t("Rendering video"),
- "mixing audio" => t("Mixing audio"),
- "muxing" => t("Finalising file"),
- other => other.to_owned(),
- };
- on_ui(move |studio, _, _| {
- if studio.export.phase == ExportPhase::Running {
- studio.export.progress = fraction.clamp(0.0, 1.0);
- studio.export.stage = stage;
- }
- });
- })
- },
- |studio, _, _, result| match result {
- Ok(written) => {
- studio.export.phase = ExportPhase::Done;
- studio.export.progress = 1.0;
- studio.export.written = written;
- studio.notify(&t("Export finished"), false);
- }
- Err(error) => {
- if studio.export.phase == ExportPhase::Idle {
- // Cancelled: the sheet already went back to idle.
- return;
- }
- studio.export.phase = ExportPhase::Failed;
- studio.export.message = error.clone();
- studio.notify(&tf("Export failed: {0}", &[&error]), true);
- }
- },
- );
- }
-
- pub fn export_cancel(&mut self) {
- self.host.exporter.cancel();
- self.export.phase = ExportPhase::Idle;
- self.export.progress = 0.0;
+ }
}
// ── speech ──
@@ -6998,7 +6825,7 @@ impl Studio {
sync(&models.menu, rows);
editor.set_menu_token(self.menu_token);
- app.set_export(self.export_data());
+ app.set_export(self.export.data(self));
app.set_settings(SettingsData {
open: self.settings.open,
tab: self.settings.tab,
@@ -7133,84 +6960,6 @@ impl Studio {
}
}
- fn export_data(&self) -> ExportData {
- let (width, height) = self.export_size();
- let (num, den) = EXPORT_RATES[self.export.rate.min(2)];
- let rate = num as f32 / den as f32;
- let clips = self.timeline().clips.len();
- let titles = self
- .timeline()
- .clips
- .iter()
- .filter(|clip| clip.kind == model::ClipKind::Text)
- .count();
- ExportData {
- open: self.export.open,
- name: self.export.name.as_str().into(),
- path: format!(
- "{}/{}.mp4",
- self.export.folder.trim_end_matches('/'),
- self.export.name
- )
- .into(),
- format: format!("{width} × {height} · {rate:.2} fps").into(),
- duration: {
- let whole = self.duration().max(0.0) as i32;
- format!("{}:{:02}", whole / 60, whole % 60).into()
- },
- contents: if titles > 0 {
- format!("{clips} clips · {titles} titles")
- } else {
- format!("{clips} clips")
- }
- .into(),
- resolution: self.export.resolution as i32,
- rate: self.export.rate as i32,
- quality: self.export.quality as i32,
- codec: self.export.codec as i32,
- ten_bit: self.export.ten_bit,
- encoding: {
- // "HEVC 10-bit · hardware": the standard, the depth when it
- // is the deeper one, and whether the platform's own encoder
- // will be doing it.
- let codec = self.export_codec();
- let mut words = vec![codec.label().to_owned()];
- if self.export.ten_bit {
- words.push("10-bit".to_owned());
- }
- if codec
- .encoders(true)
- .first()
- .is_some_and(|name| name.ends_with("_videotoolbox"))
- {
- words.push(format!("· {}", t("hardware")));
- }
- words.join(" ")
- }
- .into(),
- size_high: bytes(self.export_size_bytes(0)).into(),
- size_balanced: bytes(self.export_size_bytes(1)).into(),
- size_small: bytes(self.export_size_bytes(2)).into(),
- phase: self.export.phase,
- progress: self.export.progress,
- stage: self.export.stage.as_str().into(),
- eta: if self.export.phase == ExportPhase::Running && self.export.progress > 0.02 {
- self.export
- .started_at
- .map(|started| {
- let elapsed = started.elapsed().as_secs_f32();
- eta(elapsed / self.export.progress * (1.0 - self.export.progress)).into()
- })
- .unwrap_or_default()
- } else {
- SharedString::new()
- },
- message: self.export.message.as_str().into(),
- done_size: bytes(self.export_size_bytes(self.export.quality)).into(),
- empty: clips == 0,
- }
- }
-
fn model_rows(models: &[ModelState]) -> Vec<ModelData> {
models
.iter()