Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetExportSession estimatedOutputFileLength always returns 0

Having a problem where the estimatedOutputFileLength property of AVAssetExportSession always returns 0 (and returns -9223372036854775808 on the simulator).

I've tried everything to get this to work, trying different outputFileTypes, toggling shouldOptimizeForNetworkUse on and off, specifying (or not specifying) the outputURL... despite all this, nothing seems to work and I'm beginning to think 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 figure out why this isn't working! (iOS 6, iPhone 5)

like image 950
Jonathan Ellis Avatar asked Jan 14 '23 12:01

Jonathan Ellis


2 Answers

You can workaround this problem by setting proper timeRange on the exportSession:

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

It seems that in iOS, the AVAssetExportSessionInternal.timeRange is not getting sensible result when estimating file length.

like image 164
liuliu Avatar answered Jan 17 '23 02:01

liuliu


You need to include the timerange.

How much of the file you intend to export. Without that 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;
like image 21
Ryan Heitner Avatar answered Jan 17 '23 00:01

Ryan Heitner