Use toolbox video compressor (#11246)
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import {getVideoMetaData, Video} from 'react-native-compressor'
|
||||
import {type ImagePickerAsset} from 'expo-image-picker'
|
||||
import {compress, probe, type VideoMetadata} from '@bsky.app/video-compressor'
|
||||
|
||||
import {SUPPORTED_MIME_TYPES, type SupportedMimeTypes} from '#/lib/constants'
|
||||
import {logger} from '#/logger'
|
||||
import {probe} from '../../../../modules/expo-bluesky-video-compress'
|
||||
import {
|
||||
COMPRESSION_MAX_DIMENSION,
|
||||
COMPRESSION_TARGET_BITRATE,
|
||||
} from './constants'
|
||||
import {type CompressedVideo, type ProbedMetadata} from './types'
|
||||
import {extToMime} from './util'
|
||||
|
||||
const MIN_SIZE_FOR_COMPRESSION_BYTES = 25 * 1024 * 1024 // 25mb
|
||||
|
||||
@@ -23,7 +25,7 @@ export async function compressVideo(
|
||||
// future smart-skip thresholds. Failures must not block the upload.
|
||||
if (onProbe && file.mimeType !== 'image/gif') {
|
||||
try {
|
||||
onProbe(await probe(file.uri))
|
||||
onProbe(toProbedMetadata(await probe(file.uri)))
|
||||
} catch (e) {
|
||||
logger.debug('video probe failed', {safeMessage: e})
|
||||
}
|
||||
@@ -60,31 +62,27 @@ export async function compressVideo(
|
||||
}
|
||||
}
|
||||
|
||||
const compressed = await Video.compress(
|
||||
return compress(
|
||||
file.uri,
|
||||
{
|
||||
compressionMethod: 'manual',
|
||||
bitrate: 3_000_000, // 3mbps
|
||||
maxSize: 1920,
|
||||
targetBitrate: COMPRESSION_TARGET_BITRATE,
|
||||
maxSize: COMPRESSION_MAX_DIMENSION,
|
||||
codec: 'auto',
|
||||
frameRateCap: 30,
|
||||
mimeType: file.mimeType,
|
||||
fileSize: file.fileSize,
|
||||
// Force a transcode for unacceptable-format files regardless of size.
|
||||
// rnc's default minimumFileSizeForCompress would otherwise pass small
|
||||
// The compressor's default threshold would otherwise pass small
|
||||
// unacceptable-format files through unchanged and the server would
|
||||
// reject them. Acceptable formats are already short-circuited above so
|
||||
// they never reach this call.
|
||||
// WARNING: this ONE SPECIFIC ARG is in MB -sfn
|
||||
minimumFileSizeForCompress: 0,
|
||||
getCancellationId: id => {
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', () => {
|
||||
Video.cancelCompression(id)
|
||||
})
|
||||
}
|
||||
},
|
||||
passthroughBelowBytes: 0,
|
||||
passthroughGif: false,
|
||||
},
|
||||
onProgress,
|
||||
{onProgress, signal},
|
||||
)
|
||||
|
||||
const info = await getVideoMetaData(compressed)
|
||||
|
||||
return {uri: compressed, size: info.size, mimeType: extToMime(info.extension)}
|
||||
}
|
||||
|
||||
function toProbedMetadata(metadata: VideoMetadata): ProbedMetadata {
|
||||
return metadata
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user