Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(export): take the output shape from the scene, never a hardcoded 16:9

EtienneLescot9d5a1a38df2b
diff --git a/crates/compositor-view-napi/src/lib.rs b/crates/compositor-view-napi/src/lib.rs
index 69476ffc2..d04eb2098 100644
--- a/crates/compositor-view-napi/src/lib.rs
+++ b/crates/compositor-view-napi/src/lib.rs
@@ -366,9 +366,73 @@ pub struct ClipInput {
pub has_audio: bool,
}
+/// The export's pixel size. The SHAPE belongs to the scene: `scene.output` is what the live
+/// preview is sized from (`live.rs::preview_render_size`), so it is the only geometry an export
+/// may have. Absent width/height take `scene.output`; a size of another shape is refused, because
+/// the compositor would otherwise lay the preview's frame out on a different canvas and the file
+/// would silently disagree with what the user saw (a 9:16 project exported 16:9). Only without a
+/// scene does `default` apply. Both axes are snapped to even pixels (NV12 4:2:0).
+fn resolve_output_size(
+ scene: Option<&Scene>,
+ width: Option<u32>,
+ height: Option<u32>,
+ default: (u32, u32),
+) -> Result<(u32, u32)> {
+ let even = |v: u32| v.max(2) & !1;
+ let Some(scene) = scene else {
+ return Ok((
+ even(width.unwrap_or(default.0)),
+ even(height.unwrap_or(default.1)),
+ ));
+ };
+ let (ow, oh) = (
+ scene.output.width.max(1) as u64,
+ scene.output.height.max(1) as u64,
+ );
+ let (Some(w), Some(h)) = (width, height) else {
+ return Ok((even(ow as u32), even(oh as u32)));
+ };
+ let (w, h) = (even(w), even(h));
+ // 3% absorbs even-pixel snapping on small GIF sizes; a real shape change is far beyond it.
+ if (w as u64 * oh).abs_diff(h as u64 * ow) * 100 > 3 * h as u64 * ow {
+ return Err(Error::from_reason(format!(
+ "export size {w}x{h} does not match the scene's output frame {ow}x{oh}"
+ )));
+ }
+ Ok((w, h))
+}
+
+#[cfg(test)]
+mod output_size_tests {
+ use super::*;
+
+ fn portrait_scene() -> Scene {
+ Scene::from_json(r##"{"clips":[],"layout":{"preset":"no-webcam","webcamSize":1,"webcamShape":"rectangle","webcamMirror":false,"webcamPosition":null,"webcamReactiveZoom":false},"effects":{"padding":0,"blur":false,"shadow":0,"roundnessFrac":0,"motionBlur":0},"background":{"kind":"color","color":"#000000"},"zoomRegions":[],"cursor":{"show":false,"size":1,"smoothing":0,"motionBlur":0,"clickBounce":0,"clipToBounds":false,"theme":"default"},"cropByClip":[],"output":{"width":1080,"height":1920,"fps":null}}"##).expect("parse")
+ }
+
+ #[test]
+ fn export_size_follows_the_scene_shape() {
+ let scene = portrait_scene();
+ // No size sent: the scene's frame, never the 1920x1080 default (the 9:16 → 16:9 bug).
+ assert_eq!(
+ resolve_output_size(Some(&scene), None, None, (1920, 1080)).unwrap(),
+ (1080, 1920)
+ );
+ // Same shape at another resolution (quality tier, GIF cap) is accepted.
+ assert_eq!(
+ resolve_output_size(Some(&scene), Some(720), Some(1280), (1920, 1080)).unwrap(),
+ (720, 1280)
+ );
+ assert!(resolve_output_size(Some(&scene), Some(270), Some(480), (1920, 1080)).is_ok());
+ // Another shape would stretch the preview's layout: refused.
+ assert!(resolve_output_size(Some(&scene), Some(1920), Some(1080), (1920, 1080)).is_err());
+ // Without a scene the default still applies.
+ assert_eq!(resolve_output_size(None, None, None, (854, 480)).unwrap(), (854, 480));
+ }
+}
+
/// Taille/cadence/codec de sortie voulus par l'app (modale d'export). Tous optionnels :
-/// absent → comportement historique (1920x1080, fps du 1er clip, h264). `width`/`height`
-/// sont arrondis au pair le plus proche (exigence NV12 4:2:0) côté `export_multi`.
+/// taille absente → `scene.output` (cf. `resolve_output_size`), fps du 1er clip, h264.
#[napi(object)]
pub struct ExportParamsInput {
pub width: Option<u32>,
@@ -421,13 +485,15 @@ impl Task for ExportMultiTask {
}
let mut export_params = pipeline::ExportParams::default();
+ let (width, height) = resolve_output_size(
+ scene.as_ref(),
+ self.params.as_ref().and_then(|p| p.width),
+ self.params.as_ref().and_then(|p| p.height),
+ (export_params.width, export_params.height),
+ )?;
+ export_params.width = width;
+ export_params.height = height;
if let Some(p) = &self.params {
- if let Some(w) = p.width {
- export_params.width = w.max(2) & !1; // pair le plus proche (>=2, NV12)
- }
- if let Some(h) = p.height {
- export_params.height = h.max(2) & !1;
- }
export_params.fps = p.fps;
if let Some(codec) = &p.codec {
export_params.codec = match codec.as_str() {
@@ -589,14 +655,18 @@ impl Task for ExportGifTask {
cfg.cursor = false;
}
- let width = self
- .params
- .width
- .unwrap_or(openscreen_compositor::gif_export::DEFAULT_GIF_WIDTH);
- let height = self
- .params
- .height
- .unwrap_or(openscreen_compositor::gif_export::DEFAULT_GIF_HEIGHT);
+ let (width, height) = resolve_output_size(
+ scene.as_ref(),
+ self.params.width,
+ self.params.height,
+ (
+ openscreen_compositor::gif_export::DEFAULT_GIF_WIDTH,
+ openscreen_compositor::gif_export::DEFAULT_GIF_HEIGHT,
+ ),
+ )?;
+ // `export_gif` reads its size back from the params; keep them the resolved one.
+ self.params.width = Some(width);
+ self.params.height = Some(height);
let comp = Compositor::new_sized(&gpu, width, height)
.map_err(|e| Error::from_reason(format!("{e:#}")))?;
if let Some(scene) = &scene {
diff --git a/src/components/ai-edition/ExportDialog.tsx b/src/components/ai-edition/ExportDialog.tsx
index 5dff50acf..f104f65bb 100644
--- a/src/components/ai-edition/ExportDialog.tsx
+++ b/src/components/ai-edition/ExportDialog.tsx
@@ -16,6 +16,7 @@ import {
collectEffectiveClipDims,
type Dims,
pickExtremeDims,
+ referenceClipDims,
resolveAspectRatioValue,
} from "@/lib/ai-edition/document/outputFormat";
import type { AxcutDocument } from "@/lib/ai-edition/schema";
@@ -178,9 +179,14 @@ export function ExportDialog({ open, onClose, document }: ExportDialogProps) {
// SMALLEST clip's own resolution means no clip on the timeline is ever upscaled past its
// true footprint by picking Source. It also feeds the upscale badge on the fixed
// 720p/1080p tiers, which can still genuinely upscale a small clip.
+ // Never null while there is a document: with no probed dims, `referenceClipDims` is the same
+ // fallback the scene's output frame is built from. A null here used to send no size at all,
+ // and the native side then encoded its own 1920x1080, a 16:9 file for a 9:16 preview.
const smallestSource = useMemo(
- () => pickExtremeDims(effectiveClipDims, "smallest"),
- [effectiveClipDims],
+ () =>
+ pickExtremeDims(effectiveClipDims, "smallest") ??
+ (document ? referenceClipDims(document) : null),
+ [effectiveClipDims, document],
);
// Aspect the export normalizes to: the timeline's selected ratio (mirrors documentExporter),