iOS计算视频长度

作者: 筱笑 | 来源:发表于2016-08-24 15:41 被阅读332次

添加#import <AVFoundation/AVFoundation.h>头文件

//计算视频长度  (秒)
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计算视频长度

    本文链接:https://www.haomeiwen.com/subject/ttkosttx.html