Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions apps/web/src/components/editor/export-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import { Check, Copy, Download, RotateCcw } from "lucide-react";
import {
EXPORT_FORMAT_VALUES,
EXPORT_QUALITY_VALUES,
PLATFORM_PRESET_VALUES,
PLATFORM_PRESETS,
type ExportFormat,
type ExportQuality,
type PlatformPreset,
} from "@/lib/export";
import {
Section,
Expand All @@ -43,6 +46,12 @@ function isExportQuality(value: string): value is ExportQuality {
return EXPORT_QUALITY_VALUES.some((qualityValue) => qualityValue === value);
}

function isPlatformPreset(value: string): value is PlatformPreset {
return PLATFORM_PRESET_VALUES.some(
(presetValue) => presetValue === value,
);
}

export function ExportButton() {
const [isExportPopoverOpen, setIsExportPopoverOpen] = useState(false);
const editor = useEditor();
Expand Down Expand Up @@ -101,6 +110,8 @@ function ExportPopover({
const activeProject = useEditor((e) => e.project.getActive());
const exportState = useEditor((e) => e.project.getExportState());
const { isExporting, progress, result: exportResult } = exportState;
const [platformPreset, setPlatformPreset] =
useState<PlatformPreset>("custom");
const [format, setFormat] = useState<ExportFormat>(
DEFAULT_EXPORT_OPTIONS.format,
);
Expand All @@ -111,15 +122,32 @@ function ExportPopover({
DEFAULT_EXPORT_OPTIONS.includeAudio ?? true,
);

const handlePlatformPresetChange = (value: string) => {
if (!isPlatformPreset(value)) return;
setPlatformPreset(value);
if (value !== "custom") {
const preset = PLATFORM_PRESETS[value];
setFormat(preset.format);
setQuality(preset.quality);
}
};

const handleExport = async () => {
if (!activeProject) return;

const presetConfig =
platformPreset !== "custom"
? PLATFORM_PRESETS[platformPreset]
: undefined;

const result = await editor.project.export({
options: {
format,
quality,
fps: activeProject.settings.fps,
includeAudio: shouldIncludeAudio,
width: presetConfig?.width,
height: presetConfig?.height,
},
});

Expand Down Expand Up @@ -163,6 +191,63 @@ function ExportPopover({
{!isExporting && (
<>
<div className="flex flex-col">
<Section
collapsible
defaultOpen
showTopBorder={false}
>
<SectionHeader>
<SectionTitle>Platform</SectionTitle>
</SectionHeader>
<SectionContent>
<RadioGroup
value={platformPreset}
onValueChange={handlePlatformPresetChange}
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="custom" id="custom" />
<Label htmlFor="custom">Custom</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="youtube" id="youtube" />
<Label htmlFor="youtube">
{PLATFORM_PRESETS.youtube.label}
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="tiktok" id="tiktok" />
<Label htmlFor="tiktok">
{PLATFORM_PRESETS.tiktok.label}
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem
value="instagram_reels"
id="instagram_reels"
/>
<Label htmlFor="instagram_reels">
{PLATFORM_PRESETS.instagram_reels.label}
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem
value="instagram_post"
id="instagram_post"
/>
<Label htmlFor="instagram_post">
{PLATFORM_PRESETS.instagram_post.label}
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="twitter" id="twitter" />
<Label htmlFor="twitter">
{PLATFORM_PRESETS.twitter.label}
</Label>
</div>
</RadioGroup>
</SectionContent>
</Section>

<Section
collapsible
defaultOpen={false}
Expand All @@ -177,6 +262,7 @@ function ExportPopover({
onValueChange={(value) => {
if (isExportFormat(value)) {
setFormat(value);
setPlatformPreset("custom");
}
}}
>
Expand Down Expand Up @@ -206,6 +292,7 @@ function ExportPopover({
onValueChange={(value) => {
if (isExportQuality(value)) {
setQuality(value);
setPlatformPreset("custom");
}
}}
>
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/core/managers/renderer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class RendererManager {
onProgress?: ({ progress }: { progress: number }) => void;
onCancel?: () => boolean;
}): Promise<ExportResult> {
const { format, quality, fps, includeAudio } = options;
const { format, quality, fps, includeAudio, width: overrideWidth, height: overrideHeight } = options;

try {
const tracks = this.editor.scenes.getActiveScene().tracks;
Expand All @@ -153,7 +153,10 @@ export class RendererManager {
}

const exportFps = fps ?? activeProject.settings.fps;
const canvasSize = activeProject.settings.canvasSize;
const canvasSize = {
width: overrideWidth ?? activeProject.settings.canvasSize.width,
height: overrideHeight ?? activeProject.settings.canvasSize.height,
};

let audioBuffer: AudioBuffer | null = null;
if (includeAudio) {
Expand Down
62 changes: 62 additions & 0 deletions apps/web/src/lib/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,73 @@ export const EXPORT_FORMAT_VALUES = ["mp4", "webm"] as const;
export type ExportFormat = (typeof EXPORT_FORMAT_VALUES)[number];
export type ExportQuality = (typeof EXPORT_QUALITY_VALUES)[number];

export const PLATFORM_PRESET_VALUES = [
"custom",
"youtube",
"tiktok",
"instagram_reels",
"instagram_post",
"twitter",
] as const;

export type PlatformPreset = (typeof PLATFORM_PRESET_VALUES)[number];

export interface PlatformPresetConfig {
label: string;
width: number;
height: number;
format: ExportFormat;
quality: ExportQuality;
}
Comment on lines +27 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Platform presets are missing the fps field specified in requirements.

The PR objectives specify fps values for each platform (YouTube 30/60 fps, TikTok 30 fps, Instagram Reels 30 fps), but PlatformPresetConfig doesn't include an fps field. Currently, exports will use the project's fps setting rather than the platform-recommended fps.

Consider adding fps to the preset config:

Suggested change
+import type { FrameRate } from "opencut-wasm";
+
 export interface PlatformPresetConfig {
 	label: string;
 	width: number;
 	height: number;
 	format: ExportFormat;
 	quality: ExportQuality;
+	fps?: FrameRate;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export interface PlatformPresetConfig {
label: string;
width: number;
height: number;
format: ExportFormat;
quality: ExportQuality;
}
import type { FrameRate } from "opencut-wasm";
export interface PlatformPresetConfig {
label: string;
width: number;
height: number;
format: ExportFormat;
quality: ExportQuality;
fps?: FrameRate;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/lib/export.ts` around lines 27 - 33, PlatformPresetConfig lacks
the fps field required by the PR; add fps: number to the PlatformPresetConfig
interface and update every preset definition to include the platform-recommended
fps (e.g., YouTube 30/60, TikTok 30, Instagram Reels 30). Then update any code
that builds export settings from a preset (places that consume
PlatformPresetConfig—look for usages alongside width/height/format/quality) to
read preset.fps instead of falling back to project fps, and fix TypeScript
errors by adjusting types and tests accordingly.


export const PLATFORM_PRESETS: Record<
Exclude<PlatformPreset, "custom">,
PlatformPresetConfig
> = {
youtube: {
label: "YouTube (1920x1080)",
width: 1920,
height: 1080,
format: "mp4",
quality: "very_high",
},
tiktok: {
label: "TikTok (1080x1920)",
width: 1080,
height: 1920,
format: "mp4",
quality: "high",
},
instagram_reels: {
label: "Instagram Reels (1080x1920)",
width: 1080,
height: 1920,
format: "mp4",
quality: "high",
},
instagram_post: {
label: "Instagram Post (1080x1080)",
width: 1080,
height: 1080,
format: "mp4",
quality: "high",
},
twitter: {
label: "Twitter/X (1280x720)",
width: 1280,
height: 720,
format: "mp4",
quality: "high",
},
};

export interface ExportOptions {
format: ExportFormat;
quality: ExportQuality;
fps?: FrameRate;
includeAudio?: boolean;
width?: number;
height?: number;
}

export interface ExportResult {
Expand Down