dispose of input once finished
This commit is contained in:
@@ -7,10 +7,6 @@ import {extToMime} from './util'
|
|||||||
|
|
||||||
const MIN_SIZE_FOR_COMPRESSION = 25 // 25mb
|
const MIN_SIZE_FOR_COMPRESSION = 25 // 25mb
|
||||||
|
|
||||||
export function hasWebCodecs(): boolean {
|
|
||||||
throw new Error('Native does not have WebCodecs.')
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function compressVideo(
|
export async function compressVideo(
|
||||||
file: ImagePickerAsset,
|
file: ImagePickerAsset,
|
||||||
opts?: {
|
opts?: {
|
||||||
|
|||||||
@@ -245,16 +245,24 @@ async function doCompression(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
signal.addEventListener('abort', () => {
|
signal.addEventListener(
|
||||||
|
'abort',
|
||||||
|
() => {
|
||||||
logger.debug('compress: cancelled')
|
logger.debug('compress: cancelled')
|
||||||
conversion.cancel()
|
conversion.cancel()
|
||||||
})
|
},
|
||||||
|
{once: true},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('compress: starting conversion')
|
logger.debug('compress: starting conversion')
|
||||||
const startTime = performance.now()
|
const startTime = performance.now()
|
||||||
|
|
||||||
|
try {
|
||||||
await conversion.execute()
|
await conversion.execute()
|
||||||
|
} finally {
|
||||||
|
input.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
const elapsed = performance.now() - startTime
|
const elapsed = performance.now() - startTime
|
||||||
const bytes = target.buffer
|
const bytes = target.buffer
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ export const getVideoMetadata = (_file: File): Promise<ImagePickerAsset> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function hasWebCodecs(): boolean {
|
export function hasWebCodecs(): boolean {
|
||||||
throw new Error("hasWebCodecs is web only (also, no it doesn't)")
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ export async function getVideoMetadata(file: File): Promise<ImagePickerAsset> {
|
|||||||
if (hasWebCodecs()) {
|
if (hasWebCodecs()) {
|
||||||
try {
|
try {
|
||||||
const result = await getMetadataWithWebCodecs(file, blobUrl)
|
const result = await getMetadataWithWebCodecs(file, blobUrl)
|
||||||
logger.debug('metadata: MediaBunny succeeded', {
|
logger.debug('metadata: WebCodecs succeeded', {
|
||||||
width: result.width,
|
width: result.width,
|
||||||
height: result.height,
|
height: result.height,
|
||||||
duration: result.duration,
|
duration: result.duration,
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn('metadata: MediaBunny failed, using fallback', {
|
logger.warn('metadata: WebCodecs failed, using fallback', {
|
||||||
safeMessage: e,
|
safeMessage: e,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user