【问题标题】:How to find the memory size an exported movie takes on iOS?如何找到导出的电影在 iOS 上占用的内存大小?
【发布时间】: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


【解决方案1】:

尝试在你需要的estimatedOutputFileLength之前添加你想要导出的媒体范围

CMTime full = CMTimeMultiplyByFloat64(exportSession.asset.duration, 1);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, full);

见下文 你也不能使用 AVAssetExportPresetPassthrough,因为

/* 表示导出文件的估计字节大小。当导出预设为 AVAssetExportPresetPassthrough 或 AVAssetExportPresetAppleProRes422LPCM 时返回零。如果尚未设置 timeRange 属性的数值(即非无效、不确定或无限),此属性也将返回零。 */

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2012-06-08
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多