iOS计算视频长度

添加#import 头文件

//计算视频长度  (秒)
NSURL *url = [NSURL URLWithString:@"http://wvideo.spriteapp.cn/video/2016/0328/56f8ec01d9bfe_wpd.mp4"];
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
NSInteger totalSecond = urlAsset.duration.value / urlAsset.duration.timescale;
NSLog(@"计算视频长度 = %ld",(long)totalSecond);

你可能感兴趣的:(iOS计算视频长度)