我正在使用a编写带有AVAssetWriter的MP4视频文件AVAssetWriterInputPixelBufferAdaptor.
来源是a的视频UIImagePickerController,可以从相机或资产库中新近捕获.现在质量是UIImagePickerControllerQualityTypeMedium.
有时候作家失败了.它的状态是AVAssetWriterStatusFailed,AVAssetWriter对象的错误属性是:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo=0xf5d8990 {NSLocalizedFailureReason=An unknown error occurred (-536870210),
NSUnderlyingError=0x4dd8e0 "The operation couldn’t be completed. (OSStatus error -536870210.)",
NSLocalizedDescription=The operation could not be completed
Run Code Online (Sandbox Code Playgroud)
错误发生在代码运行的大约20%的时间.它似乎在iPhone 4/4S上比在iPhone 5上更频繁地失败.
如果源视频质量较高,它也会更频繁地出现.使用UIImagePickerControllerQualityTypeLow,错误不会经常发生.使用UIImagePickerControllerQualityTypeHigh,错误更频繁地发生.
我还注意到了其他一些事情:它似乎有点波澜.当它失败时,即使我删除了应用程序并重新安装它,以下运行也经常会失败.这让我想知道,我的程序是否泄漏了一些内存,即使应用程序被杀,该内存是否仍然存活(甚至可能?).
这是我用来渲染视频的代码:
- (void)writeVideo
{
offlineRenderingInProgress = YES;
/* --- Writer Setup --- */
[locationQueue cancelAllOperations];
[self stopWithoutRewinding];
NSError *writerError = nil;
BOOL succes;
succes = [[NSFileManager defaultManager] removeItemAtURL:self.outputURL error:nil];
// DLog(@"Url: %@, …Run Code Online (Sandbox Code Playgroud)