AVAssetExportSession estimatedOutputFileLength始终返回0

时间:2013-01-14 23:15:57

标签: iphone ios objective-c cocoa-touch avfoundation

问题是estimatedOutputFileLength AVAssetExportSession属性始终返回 0 (并在模拟器上返回 -9223372036854775808 )。

我已经尝试了一切来实现这一点,尝试不同的outputFileType,打开和关闭shouldOptimizeForNetworkUse,指定(或不指定)outputURL ...尽管所有这似乎没什么用,我开始认为这可能是SDK中的一个错误。

这是我的代码:

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality]; // doesn't matter which preset is used
//exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"bytes = %lld", exportSession.estimatedOutputFileLength);

我只是想不通为什么这不起作用! (iOS 6,iPhone 5)

2 个答案:

答案 0 :(得分:7)

您可以通过在exportSession上设置正确的timeRange来解决此问题:

exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);

似乎在iOS中,AVAssetExportSessionInternal.timeRange在估计文件长度时没有得到明智的结果。

答案 1 :(得分:1)

您需要包含时间范围。

您要导出多少文件。没有它,它将返回0,

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetAppleM4A];
exporter.outputFileType = AVFileTypeAppleM4A;

CMTime full = CMTimeMultiplyByFloat64(exporter.asset.duration, 1);
exporter.timeRange = CMTimeRangeMake(kCMTimeZero, full);
long long size = exporter.estimatedOutputFileLength;
fileInfo.fileSize = size;