在播放时获取视频的方向

时间:2016-02-17 12:46:44

标签: ios iphone ios7 ios9 uiinterfaceorientation

可以在播放时获得视频方向。如果我在视频模式下录制了一半视频而在视频模式中录制了一半,我在面对问题时遇到问题。如果视频包含纵向和横向模式,那么我想将横向帧转换为纵向。任何人都可以帮我解决这个问题吗?提前致谢

1 个答案:

答案 0 :(得分:0)

最初从视频中获取缩略图

- (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";
  }