From f40ff6250a5b1bf44e9a9624b512ca968824d287 Mon Sep 17 00:00:00 2001 From: vineyardbovines Date: Mon, 22 Jun 2026 15:17:47 -0400 Subject: [PATCH] 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. --- src/lib/media/video/compress.ts | 27 ++++++++++++++++----------- src/lib/media/video/constants.ts | 8 ++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/lib/media/video/constants.ts diff --git a/src/lib/media/video/compress.ts b/src/lib/media/video/compress.ts index ad593938d9..826419e789 100644 --- a/src/lib/media/video/compress.ts +++ b/src/lib/media/video/compress.ts @@ -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)`) diff --git a/src/lib/media/video/constants.ts b/src/lib/media/video/constants.ts new file mode 100644 index 0000000000..6aa98f731a --- /dev/null +++ b/src/lib/media/video/constants.ts @@ -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