Move compression thresholds to a feature-local constants file

Per Frontend Spec (A2.4 pre-merge note): MAX_UPLOAD_SIZE was hardcoded to
100 MB and would force-compress 100-300 MB files that should skip. Reads
from VIDEO_MAX_SIZE now. Pulled the target/passthrough bitrate and max
dimension out of compress.ts into src/lib/media/video/constants.ts so the
compression contract lives in one place without bloating the global
constants file.
This commit is contained in:
vineyardbovines
2026-06-22 15:17:47 -04:00
parent fd387904d4
commit f40ff6250a
2 changed files with 24 additions and 11 deletions
+16 -11
View File
@@ -1,14 +1,19 @@
import {type ImagePickerAsset} from 'expo-image-picker'
import {SUPPORTED_MIME_TYPES, type SupportedMimeTypes} from '#/lib/constants'
import {
SUPPORTED_MIME_TYPES,
type SupportedMimeTypes,
VIDEO_MAX_SIZE,
} from '#/lib/constants'
import {logger} from '#/logger'
import {compress, probe} from '../../../../modules/expo-bluesky-video-compress'
import {
COMPRESSION_MAX_DIMENSION,
COMPRESSION_PASSTHROUGH_BITRATE,
COMPRESSION_TARGET_BITRATE,
} from './constants'
import {type CompressedVideo} from './types'
const PASSTHROUGH_BITRATE = 5_000_000
const PASSTHROUGH_MAX_DIMENSION = 1920
const MAX_UPLOAD_SIZE = 100 * 1000 * 1000
export async function compressVideo(
file: ImagePickerAsset,
opts?: {
@@ -49,8 +54,8 @@ export async function compressVideo(
const result = await compress(
file.uri,
{
targetBitrate: 3_000_000,
maxSize: PASSTHROUGH_MAX_DIMENSION,
targetBitrate: COMPRESSION_TARGET_BITRATE,
maxSize: COMPRESSION_MAX_DIMENSION,
codec: 'h264',
},
{
@@ -92,14 +97,14 @@ function shouldCompress(
return true
}
if (metadata.fileSize > MAX_UPLOAD_SIZE) {
if (metadata.fileSize > VIDEO_MAX_SIZE) {
logger.debug(`shouldCompress: yes (file too large: ${sizeMB}MB)`)
return true
}
if (
metadata.bitrate <= PASSTHROUGH_BITRATE &&
maxDimension <= PASSTHROUGH_MAX_DIMENSION
metadata.bitrate <= COMPRESSION_PASSTHROUGH_BITRATE &&
maxDimension <= COMPRESSION_MAX_DIMENSION
) {
logger.debug(
`shouldCompress: no (${bitrateKbps}kbps, ${maxDimension}px, ${sizeMB}MB)`,
@@ -107,7 +112,7 @@ function shouldCompress(
return false
}
if (metadata.bitrate > PASSTHROUGH_BITRATE) {
if (metadata.bitrate > COMPRESSION_PASSTHROUGH_BITRATE) {
logger.debug(`shouldCompress: yes (bitrate ${bitrateKbps}kbps)`)
} else {
logger.debug(`shouldCompress: yes (dimension ${maxDimension}px)`)
+8
View File
@@ -0,0 +1,8 @@
// Target encode bitrate when we do compress. Matches the web path.
export const COMPRESSION_TARGET_BITRATE = 3_000_000 // 3mbps
// Source files at or under this bitrate skip compression (paired with
// COMPRESSION_MAX_DIMENSION). Slightly above the encode target so we
// don't re-encode files that are already close to what we'd produce.
export const COMPRESSION_PASSTHROUGH_BITRATE = 5_000_000 // 5mbps
// Output dimension cap when compressing, and skip threshold for source files.
export const COMPRESSION_MAX_DIMENSION = 1920