AVFoundation相关
【AVFoundation相关】AVFoundation
AVAsset:多媒体载体类
AVAssetTrack:track id是唯一性标识符。每个视频至少两个track,(音频轨和视频轨)Atom Inspector可以查看视频文件的详细信息!
将视频文件写入Caches/videos文件夹
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDirectory = [paths objectAtIndex:0];
NSString *dataPath = [cachesDirectory stringByAppendingPathComponent:@"/videos"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init] ;
[dateFormat setDateFormat:@"dd-MM-yyyyHH:mm:SS"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
NSData *videoData = https://www.it610.com/article/[NSData dataWithContentsOfURL:srcVideo] ;
NSString *videopath= [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/%@_Origin.mp4",dataPath,theDate]];
BOOL success = [videoData writeToFile:videopath atomically:NO];
NSLog(@"Successs:::: %@", success ? @"YES" : @"NO");
NSLog(@"video path --> %@",videopath);
* 视频方向:关于Rotation的0、90、180和270这四个角度值可以这样理解:LandscapeRigth为0度;以Home键或摄像头为圆心,顺时针旋转到Portrait为90度;旋转到LandscapeLeft为180度;旋转到PortraitUpsideDown为270度。视频是默认横屏拍摄,此时长边叫width=1920,height=1080注意坐标原点的变动。判断原始视频的拍摄角度:+ (NSUInteger)degressFromVideoFileWithURL:(NSURL *)url{NSUInteger degress = 0;
AVAsset *asset = [AVAsset assetWithURL:url];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if([tracks count] > 0) {AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
CGAffineTransform t = videoTrack.preferredTransform;
if(t.a == 0 && t.b == 1.0 && t.c == -1.0 && t.d == 0){// Portraitdegress = 90;
}else if(t.a == 0 && t.b == -1.0 && t.c == 1.0 && t.d == 0){// PortraitUpsideDowndegress = 270;
}else if(t.a == 1.0 && t.b == 0 && t.c == 0 && t.d == 1.0){// LandscapeRightdegress = 0;
}else if(t.a == -1.0 && t.b == 0 && t.c == 0 && t.d == -1.0){// LandscapeLeftdegress = 180;
}}return degress;
}(NSArray*)tracksWithMediaType:(NSString *)mediaType;
tracks数组包含指定媒体类型的track。
文章图片
文章图片
推荐阅读
- 宽容谁
- 我要做大厨
- 增长黑客的海盗法则
- 画画吗()
- 2019-02-13——今天谈梦想()
- 远去的风筝
- 三十年后的广场舞大爷
- 叙述作文
- 20190302|20190302 复盘翻盘
- 学无止境,人生还很长