Video compression in composer (#4638)
Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com> Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
parent
56b688744e
commit
8f06ba70bb
23 changed files with 483 additions and 33 deletions
28
src/lib/media/video/compress.web.ts
Normal file
28
src/lib/media/video/compress.web.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import {VideoTooLargeError} from 'lib/media/video/errors'
|
||||
|
||||
const MAX_VIDEO_SIZE = 1024 * 1024 * 100 // 100MB
|
||||
|
||||
export type CompressedVideo = {
|
||||
uri: string
|
||||
size: number
|
||||
}
|
||||
|
||||
// doesn't actually compress, but throws if >100MB
|
||||
export async function compressVideo(
|
||||
file: string,
|
||||
_callbacks?: {
|
||||
onProgress: (progress: number) => void
|
||||
},
|
||||
): Promise<CompressedVideo> {
|
||||
const blob = await fetch(file).then(res => res.blob())
|
||||
const video = URL.createObjectURL(blob)
|
||||
|
||||
if (blob.size > MAX_VIDEO_SIZE) {
|
||||
throw new VideoTooLargeError()
|
||||
}
|
||||
|
||||
return {
|
||||
size: blob.size,
|
||||
uri: video,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue