How to detect if a video file was recorded in portrait orientation, or landscape in iOS

后端 未结 8 1782
孤城傲影
孤城傲影 2020-11-27 02:36

I am using AlAssetsGroup enumerateAssetsAtIndexes to list the assets in the Photos (Camera) app. For a given video asset I want to determine whether it was shot

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 03:16

    If you do not want to use AVFoundation Framework just to get the orientation of the recorded video then try it out

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
    
       NSString *orientation;
    
       NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
       NSURL *myURL = [[NSURL alloc] initFileURLWithPath:videoPath];
    
       self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:myURL];       
       UIImage *thumbImage = [movieController thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
    
       float width = thumbImage.size.width;
       float height = thumbImage.size.height;
    
       if (width > height){
    
            orientation  = @"Landscape";
    
          }else{
    
             orientation  = @"Portrait";
          }
    
     [self dismissViewControllerAnimated:YES completion:nil];
    
    }
    

提交回复
热议问题