summaryrefslogtreecommitdiff
path: root/apps/web/src/export
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/export')
-rw-r--r--apps/web/src/export/defaults.ts7
-rw-r--r--apps/web/src/export/index.ts70
-rw-r--r--apps/web/src/export/mime-types.ts4
3 files changed, 81 insertions, 0 deletions
diff --git a/apps/web/src/export/defaults.ts b/apps/web/src/export/defaults.ts
new file mode 100644
index 00000000..0247f8a8
--- /dev/null
+++ b/apps/web/src/export/defaults.ts
@@ -0,0 +1,7 @@
+import type { ExportOptions } from "./index";
+
+export const DEFAULT_EXPORT_OPTIONS = {
+ format: "mp4",
+ quality: "high",
+ includeAudio: true,
+} satisfies ExportOptions;
diff --git a/apps/web/src/export/index.ts b/apps/web/src/export/index.ts
new file mode 100644
index 00000000..c5c522b3
--- /dev/null
+++ b/apps/web/src/export/index.ts
@@ -0,0 +1,70 @@
+import type { FrameRate } from "opencut-wasm";
+import { EXPORT_MIME_TYPES } from "./mime-types";
+
+export const EXPORT_QUALITY_VALUES = [
+ "low",
+ "medium",
+ "high",
+ "very_high",
+] as const;
+
+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 interface ExportOptions {
+ format: ExportFormat;
+ quality: ExportQuality;
+ fps?: FrameRate;
+ includeAudio?: boolean;
+}
+
+export interface ExportResult {
+ success: boolean;
+ buffer?: ArrayBuffer;
+ error?: string;
+ cancelled?: boolean;
+}
+
+export interface ExportState {
+ isExporting: boolean;
+ progress: number;
+ result: ExportResult | null;
+}
+
+export function getExportMimeType({
+ format,
+}: {
+ format: ExportFormat;
+}): string {
+ return EXPORT_MIME_TYPES[format];
+}
+
+export function getExportFileExtension({
+ format,
+}: {
+ format: ExportFormat;
+}): string {
+ return `.${format}`;
+}
+
+export function downloadBuffer({
+ buffer,
+ filename,
+ mimeType,
+}: {
+ buffer: ArrayBuffer;
+ filename: string;
+ mimeType: string;
+}): void {
+ const blob = new Blob([buffer], { type: mimeType });
+ const url = URL.createObjectURL(blob);
+ const downloadLink = document.createElement("a");
+ downloadLink.href = url;
+ downloadLink.download = filename;
+ document.body.appendChild(downloadLink);
+ downloadLink.click();
+ document.body.removeChild(downloadLink);
+ URL.revokeObjectURL(url);
+}
diff --git a/apps/web/src/export/mime-types.ts b/apps/web/src/export/mime-types.ts
new file mode 100644
index 00000000..b98900bf
--- /dev/null
+++ b/apps/web/src/export/mime-types.ts
@@ -0,0 +1,4 @@
+export const EXPORT_MIME_TYPES = {
+ webm: "video/webm",
+ mp4: "video/mp4",
+} as const;