AVURLAsset getting video size

前端 未结 7 1871
礼貌的吻别
礼貌的吻别 2020-12-03 16:57

This is pretty frustrating. I\'m trying to get the size of an AVURLasset, but try to avoid naturalSize since Xcode tells me, this is deprecated in iOS5.

<
7条回答
  •  我在风中等你
    2020-12-03 17:22

    The deprecation warning says:

    Use the naturalSize and preferredTransform, as appropriate, 
    of the asset’s video tracks instead (see also tracksWithMediaType:).
    

    So we need an AVAssetTrack, and we want its naturalSize and preferredTransform. This can be accessed with the following:

    AVAssetTrack *track = [[asset tracksWithMediaType:AVMediaTypeVideo] firstObject];
    CGSize dimensions = CGSizeApplyAffineTransform(track.naturalSize, track.preferredTransform);
    

    asset is obviously your AVAsset.

提交回复
热议问题