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