diff --git a/submodules/LegacyComponents/Sources/PGVideoMovie.m b/submodules/LegacyComponents/Sources/PGVideoMovie.m index 49ecafb5c2..e27982e130 100755 --- a/submodules/LegacyComponents/Sources/PGVideoMovie.m +++ b/submodules/LegacyComponents/Sources/PGVideoMovie.m @@ -123,6 +123,21 @@ NSString *const kYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRIN #pragma mark - #pragma mark Initialization and teardown +- (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset +{ + AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; + CGSize size = [videoTrack naturalSize]; + CGAffineTransform txf = [videoTrack preferredTransform]; + + if (size.width == txf.tx && size.height == txf.ty) + return UIInterfaceOrientationLandscapeRight; + else if (txf.tx == 0 && txf.ty == 0) + return UIInterfaceOrientationLandscapeLeft; + else if (txf.tx == 0 && txf.ty == size.width) + return UIInterfaceOrientationPortraitUpsideDown; + else + return UIInterfaceOrientationPortrait; +} - (instancetype)initWithAsset:(AVAsset *)asset { @@ -554,7 +569,14 @@ NSString *const kYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRIN [currentTarget setInputSize:CGSizeMake(bufferWidth, bufferHeight) atIndex:targetTextureIndex]; [currentTarget setInputFramebuffer:outputFramebuffer atIndex:targetTextureIndex]; -// [currentTarget setInputRotation:kGPUImageRotateLeft atIndex:targetTextureIndex]; + UIInterfaceOrientation orientation = [self orientationForTrack:self.asset]; + if (orientation == UIInterfaceOrientationPortrait) { + [currentTarget setInputRotation:kGPUImageRotateRight atIndex:targetTextureIndex]; + } else if (orientation == UIInterfaceOrientationLandscapeRight) { + [currentTarget setInputRotation:kGPUImageRotate180 atIndex:targetTextureIndex]; + } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) { + [currentTarget setInputRotation:kGPUImageRotateLeft atIndex:targetTextureIndex]; + } } [outputFramebuffer unlock];