diff --git a/SDAVAssetExportSession.m b/SDAVAssetExportSession.m index e99993b..c368e20 100755 --- a/SDAVAssetExportSession.m +++ b/SDAVAssetExportSession.m @@ -305,11 +305,19 @@ - (AVMutableVideoComposition *)buildDefaultVideoComposition trackFrameRate = 30; } - videoComposition.frameDuration = CMTimeMake(1, trackFrameRate); - CGSize targetSize = CGSizeMake([self.videoSettings[AVVideoWidthKey] floatValue], [self.videoSettings[AVVideoHeightKey] floatValue]); - CGSize naturalSize = [videoTrack naturalSize]; - CGAffineTransform transform = videoTrack.preferredTransform; - // Workaround radar 31928389, see https://github.com/rs/SDAVAssetExportSession/pull/70 for more info + videoComposition.frameDuration = CMTimeMake(1, trackFrameRate); + CGSize targetSize = CGSizeMake([self.videoSettings[AVVideoWidthKey] floatValue], [self.videoSettings[AVVideoHeightKey] floatValue]); + CGSize naturalSize = [videoTrack naturalSize]; + CGAffineTransform transform = videoTrack.preferredTransform; + + // Fix for mp4 video black screen with audio, see https://github.com/rs/SDAVAssetExportSession/issues/79 for more info + CGRect rect = {{0, 0}, naturalSize}; + CGRect transformedRect = CGRectApplyAffineTransform(rect, transform); + // transformedRect should have origin at 0 if correct; otherwise add offset to correct it + transform.tx -= transformedRect.origin.x; + transform.ty -= transformedRect.origin.y; + + // Workaround radar 31928389, see https://github.com/rs/SDAVAssetExportSession/pull/70 for more info if (transform.ty == -560) { transform.ty = 0; }