Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web-recorder): add canConvertToMp4InBrowser encoder probe

Richie McIlroya27702e7ee0a
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/recording-conversion.ts b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/recording-conversion.ts
index baac4a73b..5aead94b1 100644
--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/recording-conversion.ts
+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/recording-conversion.ts
@@ -93,6 +93,37 @@ export const captureThumbnail = (
);
});
+// Firefox's WebCodecs ships no AAC encoder (and frequently no H.264 encoder),
+// so an in-browser MP4 conversion there can't produce the output and always
+// fails. Probe encoder support up front so callers can skip the doomed
+// conversion and hand the raw recording to the server instead.
+export const canConvertToMp4InBrowser = async (
+ hasAudio: boolean,
+): Promise<boolean> => {
+ if (typeof VideoEncoder === "undefined") return false;
+
+ try {
+ const video = await VideoEncoder.isConfigSupported({
+ codec: "avc1.42E01F",
+ width: 1280,
+ height: 720,
+ });
+ if (!video.supported) return false;
+
+ if (!hasAudio) return true;
+ if (typeof AudioEncoder === "undefined") return false;
+
+ const audio = await AudioEncoder.isConfigSupported({
+ codec: "mp4a.40.2",
+ sampleRate: 48000,
+ numberOfChannels: 2,
+ });
+ return audio.supported === true;
+ } catch {
+ return false;
+ }
+};
+
export const convertToMp4 = async (
blob: Blob,
hasAudio: boolean,