【发布时间】:2014-11-23 09:00:10
【问题描述】:
我正在使用 AVAssetExportSession 导出我选择的电影。如何获取导出电影实际占用的字节数?
这是我的代码中的一个 sn-p。注意我做了:“exportSession.estimatedOutputFileLength”,但它只给出 0。 另外,我需要一个确切的尺寸而不是估计的尺寸,所以即使它有效,我也不确定这是正确的方法。
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docsDir = [paths objectAtIndex:0];
NSString* targetFileName = [[mediaPath.description lastPathComponent] stringByDeletingPathExtension];
NSString* formattedFileName = [NSString stringWithFormat:@"%@.mp4", targetFileName];
NSString* videoPath = [NSString stringWithFormat:@"%@/%@", docsDir, formattedFileName];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = NO;
NSLog(@"file size = %lld", exportSession.estimatedOutputFileLength);}
【问题讨论】:
-
这样做:NSData *videoData = [NSData dataWithContentsOfURL:exportSession.outputURL]; float movieSizeInKiloBytes = (float)[videoData length] / 1024.0f;给我我需要的东西?这准确吗?
标签: ios movie avassetexportsession