From d2f39cb79cc3d2bcff389148fb08a0c532a39d85 Mon Sep 17 00:00:00 2001 From: Ramo Mujagic Date: Thu, 21 Aug 2025 12:43:40 +0200 Subject: [PATCH] change video dimensions depending on orientation --- ios/src/ImageCropPicker.mm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ios/src/ImageCropPicker.mm b/ios/src/ImageCropPicker.mm index 354ad09c8..e957c3da1 100644 --- a/ios/src/ImageCropPicker.mm +++ b/ios/src/ImageCropPicker.mm @@ -433,6 +433,16 @@ - (void) handleVideo:(AVAsset*)asset withFileName:(NSString*)fileName withLocalI if (exportSession.status == AVAssetExportSessionStatusCompleted) { AVAsset *compressedAsset = [AVAsset assetWithURL:outputURL]; AVAssetTrack *track = [[compressedAsset tracksWithMediaType:AVMediaTypeVideo] firstObject]; + + CGFloat width = track.naturalSize.width; + CGFloat height = track.naturalSize.height; + CGAffineTransform preferredTransform = track.preferredTransform; + + // Adjust width and height if video is in portrait mode + if (preferredTransform.a == 0 && preferredTransform.b == 1.0 && preferredTransform.c == -1.0 && preferredTransform.d == 0) { + width = track.naturalSize.height; + height = track.naturalSize.width; + } NSNumber *fileSizeValue = nil; [outputURL getResourceValue:&fileSizeValue @@ -448,8 +458,8 @@ - (void) handleVideo:(AVAsset*)asset withFileName:(NSString*)fileName withLocalI withSourceURL:[sourceURL absoluteString] withLocalIdentifier:localIdentifier withFilename:fileName - withWidth:[NSNumber numberWithFloat:track.naturalSize.width] - withHeight:[NSNumber numberWithFloat:track.naturalSize.height] + withWidth:[NSNumber numberWithFloat:width] + withHeight:[NSNumber numberWithFloat:height] withMime:@"video/mp4" withSize:fileSizeValue withDuration:[NSNumber numberWithFloat:milliseconds]