
有这样一种需求,从相册获取选取视频并取得视频的路径,以及将视频转换位NSData ,代码如下:
PHVideoRequestOptions *requestOptions = [[PHVideoRequestOptions alloc] init];
requestOptions.version = PHImageRequestOptionsVersionCurrent;
requestOptions.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
[[PHImageManager defaultManager] requestPlayerItemForVideo:model.asset options:requestOptions resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
NSURL *fileURL = [(AVURLAsset *)playerItem.asset URL];
NSData *videoData = [NSData dataWithContentsOfURL:fileURL];
NSLog(@"tmpData Size: %lu",videoData.length);
}];另一种方法
AVURLAsset *urlAsset = (AVURLAsset *)asset;
NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
if (videoData) {
NSLog(@"videoData Size: %lu", videoData.length);
}