赞
踩
在开发过程中我们或许需要,在文件未打开的情况下读取文件信息。或者在视频加载前读取视频编码格式,以及视频的尺寸等等。以下提供三种Object-c macOS下的实现方法:
-(void)getFileInfo:(NSString *)path{
NSFileManager *manger = [NSFileManager defaultManager];
NSDictionary *dic= [manger attributesOfItemAtPath:path error:nil];
NSLog(@"%s: \n %@",__func__,dic);
}
-(void)getVideoWithAsset:(NSString *)path
{
NSLog(@"%s",__func__);
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:path] options:nil];
NSArray *metaArray = [asset commonMetadata];
NSArray *assetTrack = [asset tracks];
for ( AVMetadataItem *item in metaArray)
NSLog(@"\n %@",item);
for (AVAssetTrack *track in assetTrack) {
NSLog(@" %f,%f",track.naturalSize.height,track.naturalSize.width);
}
}
-(void)getVideoInfoWithShell:(NSString *)path{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/mdls"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects:path, nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
NSLog (@"%s: \n%@",__func__, string);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。