播放时获取视频的方向

Get Orientation of video while playing

是否可以在播放时获取视频的方向。我在获取视频方向时遇到问题,如果我将一半视频录制为纵向模式,将一半视频录制为包含纵向和横向模式的 landscape.if 视频,那么我想将横向帧转换为纵向。任何人都可以帮我解决这个问题吗?提前致谢

最初从视频中获取缩略图

- (UIImage *)thumbnailImageFromURL:(NSURL *)videoURL
 {
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL: videoURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = NULL;
CMTime requestedTime = CMTimeMake(1, 60);     
CGImageRef imgRef = [generator copyCGImageAtTime:requestedTime actualTime:NULL error:&err];
NSLog(@"err = %@, imageRef = %@", err, imgRef);

UIImage *thumbnailImage = [[UIImage alloc] initWithCGImage:imgRef];
CGImageRelease(imgRef);    

return thumbnailImage;
}

获取缩略图后执行此操作

 UIImage *img =  [self thumbnailImageFromURL:videourl];
 float width = img.size.width;
 float height = img.size.height;

if (width > height){

    orientation  = @"Landscape";

  }else{

     orientation  = @"Portrait";
  }