Search code examples
iosiphoneios7ios9uiinterfaceorientation

Get Orientation of video while playing


is it possible to get orientation of video while playing. I am facing the problem while getting orientation of video if i have recorded half of video as on portrait mode and half of as a landscape.if video contains both portrait and landscape mode then i want to convert landscape frame to portrait. can any one plz help me out in this? Thanks in advance


Solution

  • Initially get the thumbnail from video

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

    after getting the thumbnail do this

     UIImage *img =  [self thumbnailImageFromURL:videourl];
     float width = img.size.width;
     float height = img.size.height;
    
    if (width > height){
    
        orientation  = @"Landscape";
    
      }else{
    
         orientation  = @"Portrait";
      }