我正在使用重新编码视频,AVAssetExportSession
并且我想尝试将生成的文件大小保持在限制以下。我的最后一个电话看起来像这样:
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = outputURL;
exportSession.fileLengthLimit = 600000;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.videoComposition = mainCompositionInst;
NSLog(@"bytes = %lli", exportSession.estimatedOutputFileLength);
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status])
{
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@ : %@", [[exportSession error] localizedDescription], [exportSession error]);
handler(nil);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
handler(nil);
break;
default:
handler(outputURL);
break;
}
}];
}
但是estimatedOutputFileLength 总是返回0 并且fileLengthLimit 似乎被完全忽略了。我想使用estimatedOutputFileLength 来确定是使用Medium 还是Low 质量编码。
这可能是iOS错误吗?有没有人让这两个属性工作?