Evaluating AVAssetExportSessionOutputFileLength always returns 0

There is a problem when the estimatedOutputFileLength AVAssetExportSession property always returns 0 (and returns -9223372036854775808 on the simulator).

I tried everything to make it work, trying to use different outputFileType s, switching shouldOptimizeForNetworkUse , indicating (or not indicating) outputURL ... despite all this, nothing works and I'm starting to think that this may be a bug in the SDK .

This is my code:

 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); 

I just can't understand why this is not working! (iOS 6, iPhone 5)

+4
source share
2 answers

You can solve this problem by setting the correct timeRange to exportSession:

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

It seems that in iOS, AVAssetExportSessionInternal.timeRange does not get a reasonable result when estimating file length.

+7
source

You need to enable the timer.

How many files are you going to export. Without it, it will return 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; 
+1
source

All Articles