Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

feat: add multi-language transcription and MOV file support

Augustus Otuc87b03922dde
diff --git a/apps/web/src/components/editor/InspectorPanel.tsx b/apps/web/src/components/editor/InspectorPanel.tsx
index fd0e8708..1ea5f1d5 100644
--- a/apps/web/src/components/editor/InspectorPanel.tsx
+++ b/apps/web/src/components/editor/InspectorPanel.tsx
@@ -6,7 +6,6 @@ import { useEngineStore } from "../../stores/engine-store";
import type { Transform, FitMode, Clip } from "@openreel/core";
import {
ChromaKeyEngine,
- getTranscriptionService,
initializeTranscriptionService,
type WhisperTranscriptionProgress,
type CaptionAnimationStyle,
@@ -193,6 +192,7 @@ export const InspectorPanel: React.FC = () => {
const [transcriptionProgress, setTranscriptionProgress] =
useState<WhisperTranscriptionProgress | null>(null);
const [isTranscribing, setIsTranscribing] = useState(false);
+ const [targetLanguage, setTargetLanguage] = useState("none");
const [defaultAnimationStyle, setDefaultAnimationStyle] =
useState<CaptionAnimationStyle>("word-highlight");
@@ -457,12 +457,10 @@ export const InspectorPanel: React.FC = () => {
});
try {
- let transcriptionService = getTranscriptionService();
- if (!transcriptionService) {
- transcriptionService = initializeTranscriptionService({
- apiEndpoint: OPENREEL_TTS_URL,
- });
- }
+ const transcriptionService = initializeTranscriptionService({
+ apiEndpoint: `${OPENREEL_TTS_URL}/transcribe`,
+ targetLanguage: targetLanguage !== "none" ? targetLanguage : undefined,
+ });
const regularClip = getClip(selectedClip.id);
if (!regularClip) {
@@ -512,6 +510,7 @@ export const InspectorPanel: React.FC = () => {
getClip,
addSubtitle,
defaultAnimationStyle,
+ targetLanguage,
]);
// Default transform
@@ -653,6 +652,43 @@ export const InspectorPanel: React.FC = () => {
</Select>
</div>
+ <div>
+ <label className="text-[10px] text-text-secondary block mb-1">
+ Target Language
+ </label>
+ <Select
+ value={targetLanguage}
+ onValueChange={setTargetLanguage}
+ disabled={isTranscribing}
+ >
+ <SelectTrigger className="w-full bg-background-secondary border-border text-text-primary text-[11px]">
+ <SelectValue placeholder="Original (no translation)" />
+ </SelectTrigger>
+ <SelectContent className="bg-background-secondary border-border">
+ <SelectItem value="none">Original (no translation)</SelectItem>
+ <SelectGroup>
+ <SelectLabel className="text-[10px]">Translate to</SelectLabel>
+ <SelectItem value="en">English</SelectItem>
+ <SelectItem value="es">Spanish</SelectItem>
+ <SelectItem value="fr">French</SelectItem>
+ <SelectItem value="de">German</SelectItem>
+ <SelectItem value="pt">Portuguese</SelectItem>
+ <SelectItem value="it">Italian</SelectItem>
+ <SelectItem value="nl">Dutch</SelectItem>
+ <SelectItem value="ru">Russian</SelectItem>
+ <SelectItem value="zh">Chinese</SelectItem>
+ <SelectItem value="ja">Japanese</SelectItem>
+ <SelectItem value="ko">Korean</SelectItem>
+ <SelectItem value="ar">Arabic</SelectItem>
+ <SelectItem value="hi">Hindi</SelectItem>
+ <SelectItem value="tr">Turkish</SelectItem>
+ <SelectItem value="pl">Polish</SelectItem>
+ <SelectItem value="sv">Swedish</SelectItem>
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ </div>
+
{transcriptionProgress ? (
<div className="space-y-2">
<div className="flex items-center gap-2">
diff --git a/packages/core/src/media/media-import-service.ts b/packages/core/src/media/media-import-service.ts
index d68f1aae..a298e40f 100644
--- a/packages/core/src/media/media-import-service.ts
+++ b/packages/core/src/media/media-import-service.ts
@@ -17,6 +17,7 @@ import {
getFFmpegFallback,
PROXY_THRESHOLDS,
type ProxySettings,
+ type TranscodeOptions,
} from "./ffmpeg-fallback";
export interface MediaImportOptions {
@@ -120,15 +121,27 @@ export class MediaImportService {
}
}
- if (!metadata.canDecode) {
- warnings.push(
- "Codec may not be fully supported. Playback might be limited.",
- );
+ const needsTranscode =
+ !metadata.canDecode ||
+ (file.type === "video/quicktime" &&
+ !(await this.canBrowserPlay(file)));
+
+ if (needsTranscode) {
+ if (!metadata.canDecode) {
+ warnings.push(
+ "Codec may not be fully supported. Playback might be limited.",
+ );
+ }
- // Try fallback for unsupported codec
if (opts.useFallback) {
try {
- return await this.importWithFallback(file, opts);
+ return await this.importWithFallback(file, opts, {
+ format: "mp4",
+ videoCodec: "libx264",
+ audioCodec: "aac",
+ videoBitrate: "5M",
+ audioBitrate: "192k",
+ });
} catch {
// Continue with original file, just with warning
}
@@ -258,17 +271,48 @@ export class MediaImportService {
}
}
+ private canBrowserPlay(file: File | Blob): Promise<boolean> {
+ return new Promise((resolve) => {
+ const video = document.createElement("video");
+ const url = URL.createObjectURL(file);
+ const timeout = setTimeout(() => {
+ cleanup();
+ resolve(false);
+ }, 3000);
+
+ const cleanup = () => {
+ clearTimeout(timeout);
+ video.removeAttribute("src");
+ video.load();
+ URL.revokeObjectURL(url);
+ };
+
+ video.onloadedmetadata = () => {
+ cleanup();
+ resolve(true);
+ };
+ video.onerror = () => {
+ cleanup();
+ resolve(false);
+ };
+ video.src = url;
+ });
+ }
+
private async importWithFallback(
file: File,
opts: Required<MediaImportOptions>,
+ transcodeOpts?: TranscodeOptions,
): Promise<MediaImportResult> {
- // Transcode to compatible format
const compatibleBlob =
- await this.ffmpegFallback.transcodeToCompatible(file);
+ await this.ffmpegFallback.transcodeToCompatible(file, undefined, transcodeOpts);
+ const format = transcodeOpts?.format || "webm";
+ const ext = format === "mp4" ? ".mp4" : ".webm";
+ const mime = format === "mp4" ? "video/mp4" : "video/webm";
const compatibleFile = new File(
[compatibleBlob],
- file.name.replace(/\.[^.]+$/, ".webm"),
- { type: "video/webm" },
+ file.name.replace(/\.[^.]+$/, ext),
+ { type: mime },
);
// Now process with MediaBunny
diff --git a/packages/core/src/text/transcription-service.ts b/packages/core/src/text/transcription-service.ts
index 99ba89ac..88d242e0 100644
--- a/packages/core/src/text/transcription-service.ts
+++ b/packages/core/src/text/transcription-service.ts
@@ -30,6 +30,7 @@ export interface TranscriptionConfig {
apiEndpoint: string;
apiKey?: string;
language?: string;
+ targetLanguage?: string;
maxSegmentDuration?: number;
maxWordsPerSegment?: number;
}
@@ -210,10 +211,19 @@ export class TranscriptionService {
const formData = new FormData();
formData.append("audio", audioBlob, "audio.wav");
+ if (this.config.language) {
+ formData.append("language", this.config.language);
+ }
+ if (this.config.targetLanguage) {
+ formData.append("target_language", this.config.targetLanguage);
+ }
+
onProgress?.({
phase: "transcribing",
progress: 50,
- message: "Transcribing audio...",
+ message: this.config.targetLanguage
+ ? `Transcribing and translating to ${this.config.targetLanguage}...`
+ : "Transcribing audio...",
});
const response = await fetch(this.config.apiEndpoint, {