我正在使用 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 来确定是使用中等还是低质量编码。
这可能是 iOS 错误吗?有没有人让这 2 个属性起作用?
最佳答案
为后代添加一个注释,关于 exstimatedOutputFileLength 总是返回 0,我必须向导出 session 添加一个 timeRange。
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]);
关于ios - AVAssetExportSession fileLengthLimit 被忽略并且 estimatedOutputFileLength 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20374313/