blob: f397ac4b02c77d916dc1349a9087a0180172ecae (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
import type { FrameRate } from "opencut-wasm";
import { EXPORT_MIME_TYPES } from "@/constants/export-constants";
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);
}
|