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 outputFileType
s, 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)
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With