MCPcopy
hub / github.com/CapSoftware/Cap / describeRecordingCodecs

Function describeRecordingCodecs

packages/recorder-core/src/recorder-utils.ts:223–253  ·  view source on GitHub ↗
(
	mimeType: string,
	hasAudio: boolean,
)

Source from the content-addressed store, hash-verified

221// Chromebooks) would otherwise be mislabelled, and an mp4 fallback carries aac,
222// not opus.
223export const describeRecordingCodecs = (
224 mimeType: string,
225 hasAudio: boolean,
226): { videoCodec: string; audioCodec: string | undefined } => {
227 const lowerType = mimeType.toLowerCase();
228 const codecsMatch = lowerType.match(/codecs\s*=\s*"?([^"]+)"?/);
229 const codecs = (codecsMatch?.[1] ?? "")
230 .split(",")
231 .map((codec) => codec.trim())
232 .filter(Boolean);
233 const isWebm = lowerType.includes("webm");
234 const hasCodec = (prefix: string) =>
235 codecs.some((codec) => codec.startsWith(prefix));
236
237 let videoCodec: string;
238 if (hasCodec("vp9")) videoCodec = "vp9";
239 else if (hasCodec("vp8")) videoCodec = "vp8";
240 else if (hasCodec("avc1") || hasCodec("h264")) videoCodec = "h264";
241 else videoCodec = isWebm ? "vp8" : "h264";
242
243 if (!hasAudio) {
244 return { videoCodec, audioCodec: undefined };
245 }
246
247 let audioCodec: string;
248 if (hasCodec("opus")) audioCodec = "opus";
249 else if (hasCodec("mp4a") || hasCodec("aac")) audioCodec = "aac";
250 else audioCodec = isWebm ? "opus" : "aac";
251
252 return { videoCodec, audioCodec };
253};
254
255export const isUserCancellationError = (error: unknown): boolean => {
256 if (!(error instanceof DOMException)) return false;

Callers 2

startRecordingFunction · 0.90

Calls 1

hasCodecFunction · 0.85

Tested by

no test coverage detected