通过URL获取视频的size

2019-03-28  本文已影响0人  逍遥庄主

AVPlayer videoGravity属性

AVLayerVideoGravityResizeAspect       1.保持纵横比;适合层范围内
AVLayerVideoGravityResizeAspectFill    2.保持纵横比;填充层边界
AVLayerVideoGravityResize(默认)        3.拉伸填充层边界


AVLayerVideoGravityResizeAspect是按原视频比例显示,是竖屏的就显示出竖屏的,两边留黑;
AVLayerVideoGravityResizeAspectFill是以原比例拉伸视频,直到两边屏幕都占满,但视频内容有部分就被切割了;
AVLayerVideoGravityResize是拉伸视频内容达到边框占满,但不按原比例拉伸,变形。

//获取视频宽高比
- (CGFloat )getVideoScale:(NSURL *)URL{
    //获取视频尺寸
    AVURLAsset *asset = [AVURLAsset assetWithURL:URL];
    
    NSArray *array = asset.tracks;
    CGSize videoSize = CGSizeZero;
    for (AVAssetTrack *track in array) {
        if ([track.mediaType isEqualToString:AVMediaTypeVideo]) {
            videoSize = track.naturalSize;
        }
    }
    
  return videoSize.height/videoSize.width;
}
上一篇 下一篇

猜你喜欢

热点阅读