From aec51348d4c1d4d3701b15b0d60ef623a8861b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Rodri=CC=81guez?= Date: Fri, 8 Apr 2022 07:41:41 +0200 Subject: [PATCH] fix(ios): Scale videos --- ios/Plugin/SimpleSessionExporter.swift | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/ios/Plugin/SimpleSessionExporter.swift b/ios/Plugin/SimpleSessionExporter.swift index d3722bb..64a522d 100644 --- a/ios/Plugin/SimpleSessionExporter.swift +++ b/ios/Plugin/SimpleSessionExporter.swift @@ -113,7 +113,14 @@ extension SimpleSessionExporter { start: .zero, duration: composition.duration) videoComposition.instructions = [instruction] - let layerInstruction = compositionLayerInstruction(for: compositionTrack, assetTrack: assetTrack) + + let layerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: compositionTrack) + let transform = assetTrack.preferredTransform.scaledBy( + x: videoSize.width / assetTrack.naturalSize.width, + y: videoSize.height / assetTrack.naturalSize.height + ) + layerInstruction.setTransform(transform, at: CMTime.zero) + instruction.layerInstructions = [layerInstruction] // Export @@ -144,16 +151,6 @@ extension SimpleSessionExporter { } } } - - private func compositionLayerInstruction(for track: AVCompositionTrack, assetTrack: AVAssetTrack) -> AVMutableVideoCompositionLayerInstruction { - let instruction = AVMutableVideoCompositionLayerInstruction(assetTrack: track) - let transform = assetTrack.preferredTransform - - instruction.setTransform(transform, at: .zero) - - return instruction - } - } // MARK: - AVAsset extension