Skip to content

Commit

Permalink
fix min size for compression (#5272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius authored Sep 11, 2024
1 parent 24b07c6 commit f943239
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/lib/media/video/compress.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {getVideoMetaData, Video} from 'react-native-compressor'
import {ImagePickerAsset} from 'expo-image-picker'

// import {SUPPORTED_MIME_TYPES, SupportedMimeTypes} from '#/lib/constants'
import {SUPPORTED_MIME_TYPES, SupportedMimeTypes} from '#/lib/constants'
import {extToMime} from '#/state/queries/video/util'
import {CompressedVideo} from './types'

// const MIN_SIZE_FOR_COMPRESSION = 1024 * 1024 * 25 // 25mb
const MIN_SIZE_FOR_COMPRESSION = 25 // 25mb

export async function compressVideo(
file: ImagePickerAsset,
Expand All @@ -16,21 +16,22 @@ export async function compressVideo(
): Promise<CompressedVideo> {
const {onProgress, signal} = opts || {}

// const isAcceptableFormat = SUPPORTED_MIME_TYPES.includes(
// file.mimeType as SupportedMimeTypes,
// )
const isAcceptableFormat = SUPPORTED_MIME_TYPES.includes(
file.mimeType as SupportedMimeTypes,
)

// const minimumFileSizeForCompress = isAcceptableFormat
// ? MIN_SIZE_FOR_COMPRESSION
// : 0
const minimumFileSizeForCompress = isAcceptableFormat
? MIN_SIZE_FOR_COMPRESSION
: 0

const compressed = await Video.compress(
file.uri,
{
compressionMethod: 'manual',
bitrate: 3_000_000, // 3mbps
maxSize: 1920,
// minimumFileSizeForCompress,
// WARNING: this ONE SPECIFIC ARG is in MB -sfn
minimumFileSizeForCompress,
getCancellationId: id => {
if (signal) {
signal.addEventListener('abort', () => {
Expand Down

0 comments on commit f943239

Please sign in to comment.