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 = [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){            // Portrait            degress = 90;        }else if(t.a == 0 && t.b == -1.0 && t.c == 1.0 && t.d == 0){            // PortraitUpsideDown            degress = 270;        }else if(t.a == 1.0 && t.b == 0 && t.c == 0 && t.d == 1.0){            // LandscapeRight            degress = 0;        }else if(t.a == -1.0 && t.b == 0 && t.c == 0 && t.d == -1.0){            // LandscapeLeft            degress = 180;        }    }      return degress;}(NSArray*)tracksWithMediaType:(NSString *)mediaType;

tracks数组包含指定媒体类型的track。

AVFoundation相关_第1张图片
AVFoundation相关_第2张图片

你可能感兴趣的:(AVFoundation相关)