From ec2a0b2de9b1a0266d0d635c403bdc7c278b7dd5 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 10 Nov 2026 16:46:24 +0200 Subject: [PATCH] Upload the original video when native compression fails (#12376) Co-authored-by: Claude Opus 5.5 --- src/lib/media/video/compress.ts | 70 +++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/src/lib/media/video/compress.ts b/src/lib/media/video/compress.ts index 47d6e7fb1..942607806 100644 --- a/src/lib/media/video/compress.ts +++ b/src/lib/media/video/compress.ts @@ -1,7 +1,11 @@ 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 { + SUPPORTED_MIME_TYPES, + type SupportedMimeTypes, + VIDEO_MAX_SIZE, +} from '#/lib/constants' import {logger} from '#/logger' import { COMPRESSION_MAX_DIMENSION, @@ -60,25 +64,51 @@ export async function compressVideo( } } - return compress( - file.uri, - { - 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. - // 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. - passthroughBelowBytes: 0, - passthroughGif: false, - }, - {onProgress, signal}, - ) + try { + return await compress( + file.uri, + { + 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. + // 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. + passthroughBelowBytes: 0, + passthroughGif: false, + }, + {onProgress, signal}, + ) + } catch (e) { + /* + * Like the web compressor, upload the original when encoding fails and + * the server can take the file as-is. Some iOS clips fail instantly and + * every time with "The operation could not be completed", which would + * otherwise block the post entirely. + */ + if ( + signal?.aborted || + !isAcceptableFormat || + file.fileSize == null || + file.fileSize > VIDEO_MAX_SIZE + ) { + throw e + } + logger.error('Error compressing video, uploading original', { + safeMessage: e, + }) + return { + uri: file.uri, + size: file.fileSize, + mimeType: file.mimeType ?? 'video/mp4', + passthroughReason: 'compress-error-fallback', + } + } } function toProbedMetadata(metadata: VideoMetadata): ProbedMetadata { -- knotmirror 0.0.1