-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmedia-format.js
More file actions
55 lines (46 loc) · 1.84 KB
/
Copy pathmedia-format.js
File metadata and controls
55 lines (46 loc) · 1.84 KB
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
export const DEFAULT_EXPORT_FORMAT = 'webm';
export const SUPPORTED_EXPORT_FORMATS = new Set(['webm', 'gif', 'mp4']);
const RECORDER_PROFILES = {
webm: [
{ mimeType: 'video/webm;codecs=vp9', blobType: 'video/webm', extension: 'webm' },
{ mimeType: 'video/webm;codecs=vp8', blobType: 'video/webm', extension: 'webm' },
{ mimeType: 'video/webm', blobType: 'video/webm', extension: 'webm' },
],
mp4: [
{ mimeType: 'video/mp4;codecs=avc1.42E01E', blobType: 'video/mp4', extension: 'mp4' },
{ mimeType: 'video/mp4;codecs=avc1', blobType: 'video/mp4', extension: 'mp4' },
{ mimeType: 'video/mp4', blobType: 'video/mp4', extension: 'mp4' },
],
};
export function normalizeExportFormat(format) {
return SUPPORTED_EXPORT_FORMATS.has(format) ? format : DEFAULT_EXPORT_FORMAT;
}
export function resolveRecorderProfile(
format,
isTypeSupported = (mimeType) => MediaRecorder.isTypeSupported(mimeType)
) {
const exportFormat = normalizeExportFormat(format);
const recorderFormat = exportFormat === 'gif' ? 'webm' : exportFormat;
const profiles = RECORDER_PROFILES[recorderFormat] || RECORDER_PROFILES.webm;
for (const profile of profiles) {
if (typeof isTypeSupported !== 'function' || isTypeSupported(profile.mimeType)) {
return {
exportFormat,
recorderFormat,
...profile,
};
}
}
return null;
}
export function getUnsupportedFormatMessage(format) {
const exportFormat = normalizeExportFormat(format);
if (exportFormat === 'mp4') {
return 'MP4 export is not supported in this Chrome build. Try WebM or GIF.';
}
return 'This Chrome build cannot record the selected export format.';
}
export function buildTimestampedFilename(extension, date = new Date()) {
const timestamp = date.toISOString().replace(/[:.]/g, '-').slice(0, 19);
return `scrollywood-${timestamp}.${extension}`;
}