Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix: cap MP4 export size and preview volume

webadderall8feb1dd63e87
diff --git a/package.json b/package.json
index f89ed694..3a9ee777 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
"lint:fix": "biome check --write .",
"format": "biome format --write .",
"preview": "vite preview",
- "rebuild:native": "electron-rebuild --force --only uiohook-napi",
+ "rebuild:native": "node ./node_modules/electron-rebuild/lib/src/cli.js --force --only uiohook-napi",
"build:native-helpers": "node scripts/build-native-helpers.mjs",
"build:platform-native-helpers": "npm run build:native-helpers && npm run build:windows-capture && npm run build:cursor-monitor",
"build:windows-capture": "node scripts/build-windows-capture.mjs",
diff --git a/src/components/video-editor/ExportSettingsMenu.tsx b/src/components/video-editor/ExportSettingsMenu.tsx
index 94de4331..42ee4fbb 100644
--- a/src/components/video-editor/ExportSettingsMenu.tsx
+++ b/src/components/video-editor/ExportSettingsMenu.tsx
@@ -17,6 +17,7 @@ interface ExportSettingsMenuProps {
onExportFormatChange?: (format: ExportFormat) => void;
exportQuality: ExportQuality;
onExportQualityChange?: (quality: ExportQuality) => void;
+ mp4OutputDimensions?: Record<ExportQuality, { width: number; height: number }>;
gifFrameRate: GifFrameRate;
onGifFrameRateChange?: (rate: GifFrameRate) => void;
gifLoop: boolean;
@@ -33,6 +34,7 @@ export function ExportSettingsMenu({
onExportFormatChange,
exportQuality,
onExportQualityChange,
+ mp4OutputDimensions,
gifFrameRate,
onGifFrameRateChange,
gifLoop,
@@ -92,7 +94,7 @@ export function ExportSettingsMenu({
{exportFormat === "mp4" ? (
<LayoutGroup id="header-export-quality-toggle">
- <div className="mb-3 grid h-8 w-full grid-cols-4 rounded-xl border border-white/5 bg-white/5 p-0.5">
+ <div className="mb-3 grid min-h-12 w-full grid-cols-4 rounded-xl border border-white/5 bg-white/5 p-0.5">
{([
{ value: "medium", label: tSettings("export.quality.low") },
{ value: "good", label: tSettings("export.quality.medium") },
@@ -105,7 +107,7 @@ export function ExportSettingsMenu({
key={option.value}
type="button"
onClick={() => onExportQualityChange?.(option.value)}
- className="relative rounded-lg text-[11px] font-medium transition-colors"
+ className="relative rounded-lg px-1 py-1 text-[11px] font-medium transition-colors"
>
{isActive ? (
<motion.span
@@ -114,8 +116,15 @@ export function ExportSettingsMenu({
transition={{ type: "spring", stiffness: 420, damping: 34 }}
/>
) : null}
- <span className={cn("relative z-10", isActive ? "text-black" : "text-slate-400 hover:text-slate-200")}>
- {option.label}
+ <span className="relative z-10 flex h-full flex-col items-center justify-center leading-tight">
+ <span className={cn(isActive ? "text-black" : "text-slate-400 hover:text-slate-200")}>
+ {option.label}
+ </span>
+ {mp4OutputDimensions ? (
+ <span className={cn("mt-0.5 text-[9px]", isActive ? "text-black/75" : "text-slate-500") }>
+ {mp4OutputDimensions[option.value].width} x {mp4OutputDimensions[option.value].height}
+ </span>
+ ) : null}
</span>
</button>
);
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx
index 11535e63..32feb56e 100644
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@ -17,6 +17,7 @@ import type { AppLocale } from "@/i18n/config";
import { SUPPORTED_LOCALES } from "@/i18n/config";
import {
calculateOutputDimensions,
+ DEFAULT_MP4_CODEC,
type ExportFormat,
type ExportProgress,
type ExportQuality,
@@ -25,6 +26,8 @@ import {
GifExporter,
type GifFrameRate,
type GifSizePreset,
+ probeSupportedMp4Dimensions,
+ type SupportedMp4Dimensions,
VideoExporter,
} from "@/lib/exporter";
import { matchesShortcut } from "@/lib/shortcuts";
@@ -98,6 +101,89 @@ type PendingExportSave = {
arrayBuffer: ArrayBuffer;
};
+const MP4_EXPORT_FRAME_RATE = 60;
+
+function calculateMp4SourceDimensions(
+ sourceWidth: number,
+ sourceHeight: number,
+ aspectRatio: AspectRatio,
+): { width: number; height: number } {
+ const safeSourceWidth = Math.max(2, Math.floor(sourceWidth / 2) * 2);
+ const safeSourceHeight = Math.max(2, Math.floor(sourceHeight / 2) * 2);
+ const sourceAspectRatio = safeSourceHeight > 0 ? safeSourceWidth / safeSourceHeight : 16 / 9;
+ const aspectRatioValue = getAspectRatioValue(aspectRatio, sourceAspectRatio);
+
+ if (aspectRatio === "native") {
+ return { width: safeSourceWidth, height: safeSourceHeight };
+ }
+
+ if (aspectRatioValue === 1) {
+ const baseDimension = Math.max(
+ 2,
+ Math.floor(Math.min(safeSourceWidth, safeSourceHeight) / 2) * 2,
+ );
+ return { width: baseDimension, height: baseDimension };
+ }
+
+ if (aspectRatioValue > 1) {
+ const baseWidth = safeSourceWidth;
+ for (let width = baseWidth; width >= 100; width -= 2) {
+ const height = Math.round(width / aspectRatioValue);
+ if (height % 2 === 0 && Math.abs(width / height - aspectRatioValue) < 0.0001) {
+ return { width, height };
+ }
+ }
+
+ return {
+ width: baseWidth,
+ height: Math.max(2, Math.floor(baseWidth / aspectRatioValue / 2) * 2),
+ };
+ }
+
+ const baseHeight = safeSourceHeight;
+ for (let height = baseHeight; height >= 100; height -= 2) {
+ const width = Math.round(height * aspectRatioValue);
+ if (width % 2 === 0 && Math.abs(width / height - aspectRatioValue) < 0.0001) {
+ return { width, height };
+ }
+ }
+
+ return {
+ height: baseHeight,
+ width: Math.max(2, Math.floor((baseHeight * aspectRatioValue) / 2) * 2),
+ };
+}
+
+function calculateMp4ExportDimensions(
+ baseWidth: number,
+ baseHeight: number,
+ quality: ExportQuality,
+): { width: number; height: number } {
+ if (quality === "source") {
+ return {
+ width: Math.max(2, Math.floor(baseWidth / 2) * 2),
+ height: Math.max(2, Math.floor(baseHeight / 2) * 2),
+ };
+ }
+
+ const qualityScale = quality === "medium" ? 0.6 : quality === "good" ? 0.75 : 0.9;
+ return {
+ width: Math.max(2, Math.floor((baseWidth * qualityScale) / 2) * 2),
+ height: Math.max(2, Math.floor((baseHeight * qualityScale) / 2) * 2),
+ };
+}
+
+function getSourceQualityBitrate(width: number, height: number): number {
+ const totalPixels = width * height;
+ if (totalPixels > 2560 * 1440) {
+ return 80_000_000;
+ }
+ if (totalPixels > 1920 * 1080) {
+ return 50_000_000;
+ }
+ return 30_000_000;
+}
+
function LanguageSwitcher() {
const { locale, setLocale, t } = useI18n();
const idx = SUPPORTED_LOCALES.indexOf(locale as (typeof SUPPORTED_LOCALES)[number]);
@@ -213,7 +299,14 @@ export default function VideoEditor() {
const applyingHistoryRef = useRef(false);
const pendingExportSaveRef = useRef<PendingExportSave | null>(null);
const cropSnapshotRef = useRef<CropRegion | null>(null);
+ const mp4SupportRequestRef = useRef(0);
const [historyVersion, setHistoryVersion] = useState(0);
+ const [supportedMp4SourceDimensions, setSupportedMp4SourceDimensions] = useState<SupportedMp4Dimensions>({
+ width: 1920,
+ height: 1080,
+ capped: false,
+ encoderPath: null,
+ });
const syncHistoryButtons = useCallback(() => {
setHistoryVersion((version) => version + 1);
@@ -250,6 +343,99 @@ export default function VideoEditor() {
[gifSizePreset, videoPath],
);
+ const desiredMp4SourceDimensions = useMemo(
+ () =>
+ calculateMp4SourceDimensions(
+ videoPlaybackRef.current?.video?.videoWidth || 1920,
+ videoPlaybackRef.current?.video?.videoHeight || 1080,
+ aspectRatio,
+ ),
+ [aspectRatio, duration, videoPath],
+ );
+
+ const mp4OutputDimensions = useMemo(() => {
+ const baseWidth = supportedMp4SourceDimensions.encoderPath
+ ? supportedMp4SourceDimensions.width
+ : desiredMp4SourceDimensions.width;
+ const baseHeight = supportedMp4SourceDimensions.encoderPath
+ ? supportedMp4SourceDimensions.height
+ : desiredMp4SourceDimensions.height;
+
+ return {
+ medium: calculateMp4ExportDimensions(baseWidth, baseHeight, "medium"),
+ good: calculateMp4ExportDimensions(baseWidth, baseHeight, "good"),
+ high: calculateMp4ExportDimensions(baseWidth, baseHeight, "high"),
+ source: calculateMp4ExportDimensions(baseWidth, baseHeight, "source"),
+ };
+ }, [desiredMp4SourceDimensions.height, desiredMp4SourceDimensions.width, supportedMp4SourceDimensions.encoderPath, supportedMp4SourceDimensions.height, supportedMp4SourceDimensions.width]);
+
+ const ensureSupportedMp4SourceDimensions = useCallback(async () => {
+ const result = await probeSupportedMp4Dimensions({
+ width: desiredMp4SourceDimensions.width,
+ height: desiredMp4SourceDimensions.height,
+ frameRate: MP4_EXPORT_FRAME_RATE,
+ codec: DEFAULT_MP4_CODEC,
+ getBitrate: getSourceQualityBitrate,
+ });
+
+ if (!result.encoderPath) {
+ throw new Error(
+ `Video encoding not supported on this system. Tried codec ${DEFAULT_MP4_CODEC} at up to ${desiredMp4SourceDimensions.width}x${desiredMp4SourceDimensions.height}.`,
+ );
+ }
+
+ setSupportedMp4SourceDimensions((current) => {
+ if (
+ current.width === result.width &&
+ current.height === result.height &&
+ current.capped === result.capped &&
+ current.encoderPath?.codec === result.encoderPath?.codec &&
+ current.encoderPath?.hardwareAcceleration === result.encoderPath?.hardwareAcceleration
+ ) {
+ return current;
+ }
+
+ return result;
+ });
+
+ return result;
+ }, [desiredMp4SourceDimensions.height, desiredMp4SourceDimensions.width]);
+
+ useEffect(() => {
+ let cancelled = false;
+ const requestId = mp4SupportRequestRef.current + 1;
+ mp4SupportRequestRef.current = requestId;
+ setSupportedMp4SourceDimensions({
+ width: desiredMp4SourceDimensions.width,
+ height: desiredMp4SourceDimensions.height,
+ capped: false,
+ encoderPath: null,
+ });
+
+ void ensureSupportedMp4SourceDimensions()
+ .then((result) => {
+ if (cancelled || requestId !== mp4SupportRequestRef.current) {
+ return;
+ }
+ setSupportedMp4SourceDimensions(result);
+ })
+ .catch(() => {
+ if (cancelled || requestId !== mp4SupportRequestRef.current) {
+ return;
+ }
+ setSupportedMp4SourceDimensions({
+ width: desiredMp4SourceDimensions.width,
+ height: desiredMp4SourceDimensions.height,
+ capped: false,
+ encoderPath: null,
+ });
+ });
+
+ return () => {
+ cancelled = true;
+ };
+ }, [desiredMp4SourceDimensions.height, desiredMp4SourceDimensions.width, ensureSupportedMp4SourceDimensions]);
+
const projectDisplayName = useMemo(() => {
const fileName = currentProjectPath?.split(/[\\/]/).pop() ?? "";
const withoutExtension = fileName.replace(/\.recordly$/i, "").replace(/\.[^.]+$/, "");
@@ -1628,7 +1814,7 @@ export default function VideoEditor() {
if (audio.src !== expectedSrc) {
audio.src = expectedSrc;
}
- audio.volume = Math.max(0, Math.min(1, region.volume));
+ audio.volume = Math.max(0, Math.min(1, region.volume * previewVolume));
}
return () => {
@@ -1638,7 +1824,7 @@ export default function VideoEditor() {
}
existing.clear();
};
- }, [audioRegions]);
+ }, [audioRegions, previewVolume]);
// Sync audio playback with video currentTime and isPlaying state
useEffect(() => {
@@ -1714,11 +1900,6 @@ export default function VideoEditor() {
videoPlaybackRef.current?.pause();
}
- const sourceWidth = video.videoWidth || 1920;
- const sourceHeight = video.videoHeight || 1080;
- const sourceAspectRatio = sourceHeight > 0 ? sourceWidth / sourceHeight : 16 / 9;
- const aspectRatioValue = getAspectRatioValue(aspectRatio, sourceAspectRatio);
-
// Get preview CONTAINER dimensions for scaling
const playbackRef = videoPlaybackRef.current;
const containerElement = playbackRef?.containerRef?.current;
@@ -1797,57 +1978,15 @@ export default function VideoEditor() {
} else {
// MP4 Export
const quality = settings.quality || exportQuality;
- let exportWidth: number;
- let exportHeight: number;
+ const supportedSourceDimensions = await ensureSupportedMp4SourceDimensions();
+ const { width: exportWidth, height: exportHeight } = calculateMp4ExportDimensions(
+ supportedSourceDimensions.width,
+ supportedSourceDimensions.height,
+ quality,
+ );
let bitrate: number;
if (quality === "source") {
- // Use source resolution
- exportWidth = sourceWidth;
- exportHeight = sourceHeight;
-
- if (aspectRatio === "native") {
- exportWidth = Math.floor(sourceWidth / 2) * 2;
- exportHeight = Math.floor(sourceHeight / 2) * 2;
- } else if (aspectRatioValue === 1) {
- // Square (1:1): use smaller dimension to avoid codec limits
- const baseDimension = Math.floor(Math.min(sourceWidth, sourceHeight) / 2) * 2;
- exportWidth = baseDimension;
- exportHeight = baseDimension;
- } else if (aspectRatioValue > 1) {
- // Landscape: find largest even dimensions that exactly match aspect ratio
- const baseWidth = Math.floor(sourceWidth / 2) * 2;
- let found = false;
- for (let w = baseWidth; w >= 100 && !found; w -= 2) {
- const h = Math.round(w / aspectRatioValue);
- if (h % 2 === 0 && Math.abs(w / h - aspectRatioValue) < 0.0001) {
- exportWidth = w;
- exportHeight = h;
- found = true;
- }
- }
- if (!found) {
- exportWidth = baseWidth;
- exportHeight = Math.floor(baseWidth / aspectRatioValue / 2) * 2;
- }
- } else {
- // Portrait: find largest even dimensions that exactly match aspect ratio
- const baseHeight = Math.floor(sourceHeight / 2) * 2;
- let found = false;
- for (let h = baseHeight; h >= 100 && !found; h -= 2) {
- const w = Math.round(h * aspectRatioValue);
- if (w % 2 === 0 && Math.abs(w / h - aspectRatioValue) < 0.0001) {
- exportWidth = w;
- exportHeight = h;
- found = true;
- }
- }
- if (!found) {
- exportHeight = baseHeight;
- exportWidth = Math.floor((baseHeight * aspectRatioValue) / 2) * 2;
- }
- }
-
// Calculate visually lossless bitrate matching screen recording optimization
const totalPixels = exportWidth * exportHeight;
bitrate = 30_000_000;
@@ -1857,13 +1996,6 @@ export default function VideoEditor() {
bitrate = 80_000_000;
}
} else {
- // Use quality-based target resolution
- const targetHeight = quality === "medium" ? 720 : 1080;
-
- // Calculate dimensions maintaining aspect ratio
- exportHeight = Math.floor(targetHeight / 2) * 2;
- exportWidth = Math.floor((exportHeight * aspectRatioValue) / 2) * 2;
-
// Adjust bitrate for lower resolutions
const totalPixels = exportWidth * exportHeight;
if (totalPixels <= 1280 * 720) {
@@ -1879,9 +2011,9 @@ export default function VideoEditor() {
videoUrl: videoPath,
width: exportWidth,
height: exportHeight,
- frameRate: 60,
+ frameRate: MP4_EXPORT_FRAME_RATE,
bitrate,
- codec: "avc1.640033",
+ codec: DEFAULT_MP4_CODEC,
wallpaper,
trimRegions,
speedRegions,
@@ -2317,6 +2449,7 @@ export default function VideoEditor() {
onGifLoopChange={setGifLoop}
gifSizePreset={gifSizePreset}
onGifSizePresetChange={setGifSizePreset}
+ mp4OutputDimensions={mp4OutputDimensions}
gifOutputDimensions={gifOutputDimensions}
onExport={handleStartExportFromDropdown}
className="shadow-2xl"
diff --git a/src/lib/exporter/index.ts b/src/lib/exporter/index.ts
index fb6473b2..9c10b3b8 100644
--- a/src/lib/exporter/index.ts
+++ b/src/lib/exporter/index.ts
@@ -4,6 +4,11 @@ export { StreamingVideoDecoder } from './streamingDecoder';
export { FrameRenderer } from './frameRenderer';
export { VideoMuxer } from './muxer';
export { GifExporter, calculateOutputDimensions } from './gifExporter';
+export {
+ DEFAULT_MP4_CODEC,
+ probeSupportedMp4Dimensions,
+ resolveSupportedMp4EncoderPath,
+} from './mp4Support';
export type {
ExportConfig,
ExportProgress,
@@ -16,6 +21,10 @@ export type {
GifExportConfig,
ExportSettings,
} from './types';
+export type {
+ SupportedMp4Dimensions,
+ SupportedMp4EncoderPath,
+} from './mp4Support';
export {
GIF_SIZE_PRESETS,
GIF_FRAME_RATES,
diff --git a/src/lib/exporter/mp4Support.ts b/src/lib/exporter/mp4Support.ts
new file mode 100644
index 00000000..c0975cbc
--- /dev/null
+++ b/src/lib/exporter/mp4Support.ts
@@ -0,0 +1,168 @@
+export const DEFAULT_MP4_CODEC = "avc1.640033";
+
+export type SupportedMp4EncoderPath = {
+ codec: string;
+ hardwareAcceleration: "prefer-hardware" | "prefer-software";
+};
+
+export type SupportedMp4Dimensions = {
+ width: number;
+ height: number;
+ capped: boolean;
+ encoderPath: SupportedMp4EncoderPath | null;
+};
+
+type ResolveMp4EncoderPathOptions = {
+ width: number;
+ height: number;
+ frameRate: number;
+ bitrate: number;
+ codec?: string;
+};
+
+type ProbeSupportedMp4DimensionsOptions = {
+ width: number;
+ height: number;
+ frameRate: number;
+ codec?: string;
+ getBitrate: (width: number, height: number) => number;
+};
+
+const encoderSupportCache = new Map<string, SupportedMp4EncoderPath | null>();
+const supportedDimensionCache = new Map<string, SupportedMp4Dimensions>();
+
+function normalizeEvenDimension(value: number): number {
+ return Math.max(2, Math.floor(value / 2) * 2);
+}
+
+function buildEncoderSupportCacheKey(options: ResolveMp4EncoderPathOptions): string {
+ return [
+ options.codec ?? DEFAULT_MP4_CODEC,
+ options.width,
+ options.height,
+ options.frameRate,
+ options.bitrate,
+ ].join(":");
+}
+
+function scaleDimensions(width: number, height: number, scale: number): { width: number; height: number } {
+ return {
+ width: normalizeEvenDimension(width * scale),
+ height: normalizeEvenDimension(height * scale),
+ };
+}
+
+export async function resolveSupportedMp4EncoderPath(
+ options: ResolveMp4EncoderPathOptions,
+): Promise<SupportedMp4EncoderPath | null> {
+ const codec = options.codec ?? DEFAULT_MP4_CODEC;
+ const width = normalizeEvenDimension(options.width);
+ const height = normalizeEvenDimension(options.height);
+ const cacheKey = buildEncoderSupportCacheKey({ ...options, codec, width, height });
+ const cachedResult = encoderSupportCache.get(cacheKey);
+
+ if (cachedResult !== undefined) {
+ return cachedResult;
+ }
+
+ const baseConfig: Omit<VideoEncoderConfig, "hardwareAcceleration"> = {
+ codec,
+ width,
+ height,
+ bitrate: options.bitrate,
+ framerate: options.frameRate,
+ latencyMode: "quality",
+ bitrateMode: "variable",
+ };
+
+ for (const hardwareAcceleration of ["prefer-hardware", "prefer-software"] as const) {
+ const support = await VideoEncoder.isConfigSupported({
+ ...baseConfig,
+ hardwareAcceleration,
+ });
+
+ if (support.supported) {
+ const result = { codec, hardwareAcceleration } satisfies SupportedMp4EncoderPath;
+ encoderSupportCache.set(cacheKey, result);
+ return result;
+ }
+ }
+
+ encoderSupportCache.set(cacheKey, null);
+ return null;
+}
+
+export async function probeSupportedMp4Dimensions(
+ options: ProbeSupportedMp4DimensionsOptions,
+): Promise<SupportedMp4Dimensions> {
+ const codec = options.codec ?? DEFAULT_MP4_CODEC;
+ const normalizedWidth = normalizeEvenDimension(options.width);
+ const normalizedHeight = normalizeEvenDimension(options.height);
+ const dimensionCacheKey = [codec, normalizedWidth, normalizedHeight, options.frameRate].join(":");
+ const cachedResult = supportedDimensionCache.get(dimensionCacheKey);
+
+ if (cachedResult) {
+ return cachedResult;
+ }
+
+ const requestedBitrate = options.getBitrate(normalizedWidth, normalizedHeight);
+ const directPath = await resolveSupportedMp4EncoderPath({
+ width: normalizedWidth,
+ height: normalizedHeight,
+ frameRate: options.frameRate,
+ bitrate: requestedBitrate,
+ codec,
+ });
+
+ if (directPath) {
+ const result = {
+ width: normalizedWidth,
+ height: normalizedHeight,
+ capped: false,
+ encoderPath: directPath,
+ } satisfies SupportedMp4Dimensions;
+ supportedDimensionCache.set(dimensionCacheKey, result);
+ return result;
+ }
+
+ let bestResult: SupportedMp4Dimensions | null = null;
+ let low = 1;
+ let high = 1000;
+
+ while (low <= high) {
+ const mid = Math.floor((low + high) / 2);
+ const scale = mid / 1000;
+ const candidateDimensions = scaleDimensions(normalizedWidth, normalizedHeight, scale);
+ const candidatePath = await resolveSupportedMp4EncoderPath({
+ width: candidateDimensions.width,
+ height: candidateDimensions.height,
+ frameRate: options.frameRate,
+ bitrate: options.getBitrate(candidateDimensions.width, candidateDimensions.height),
+ codec,
+ });
+
+ if (candidatePath) {
+ bestResult = {
+ width: candidateDimensions.width,
+ height: candidateDimensions.height,
+ capped: candidateDimensions.width !== normalizedWidth || candidateDimensions.height !== normalizedHeight,
+ encoderPath: candidatePath,
+ };
+ low = mid + 1;
+ } else {
+ high = mid - 1;
+ }
+ }
+
+ const result =
+ bestResult ??
+ ({
+ width: normalizedWidth,
+ height: normalizedHeight,
+ capped: false,
+ encoderPath: null,
+ } satisfies SupportedMp4Dimensions);
+
+ supportedDimensionCache.set(dimensionCacheKey, result);
+ return result;
+}
\ No newline at end of file