[英]AVAssetExportSession estimatedOutputFileLength always returns 0
遇到問題, AVAssetExportSession
的estimatedOutputFileLength
屬性總是返回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)
您可以通過在exportSession上設置正確的timeRange來解決此問題:
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
似乎在iOS中,AVAssetExportSessionInternal.timeRange在估計文件長度時沒有得到明智的結果。
您需要包含時間范圍。
您打算導出多少文件。 沒有它,它將返回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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.