【问题标题】:Get Orientation of video while playing播放时获取视频方向
【发布时间】:2016-05-29 04:25:39
【问题描述】:

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

【问题讨论】:

  • 到目前为止你尝试了什么?任何研究,任何代码?
  • 我做了研究,但没有得到任何解决方案。

标签: ios iphone ios7 ios9 uiinterfaceorientation


【解决方案1】:

最初从视频中获取缩略图

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

【讨论】:

  • 我现在可以在录制视频并在视频播放器中播放视频后以纵向和横向模式录制视频,因为我已经在横向录制了一半视频,所以我想转换视频的横向部分进入纵向模式。有可能吗?
猜你喜欢
  • 2015-02-16
  • 2016-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多