I’m using AVAssetWriter with a AVAssetWriterInputPixelBufferAdaptor to capture video from an AVCaptureSession. I’m writing the file to the App’s Caches directory. After I’m done I save the video to the camera roll.
Now here’s the problem:
Things work fine for short capture sessions from 10 to 20 mins. After about 30 mins I get this error when calling [assetWriter finishWriting]:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo=0x1a1d30 {NSLocalizedFailureReason=An unknown error occurred (268451843),
NSUnderlyingError=0x1936e0 "The operation couldn’t be completed. (OSStatus error
268451843.)", NSLocalizedDescription=The operation could not be completed}
Another interesting thing is, it actually does save the video to the camera roll, but after a certain point the video seems to be corrupt. VLC shows the length of the video to be 1 hour, but only plays the first 30min. and then cuts black.
I am clueless why its doing that.
I’m on iOS 5.0, iPhone 4S, recording with 30 FPS, 1920×1080 and using AVFileTypeMPEG4.
Any ideas?
My best practice for saving a huge files to the library is the following code (originaly from avcam by apple):
where outputFileURL is a url to the temporary camera file (which you can save on the application temp folder or documents).
You are welcome to take a look at an example project i’ve put on github: AVCam-CameraReleaseTest which seems to work on long videos (3GS iOS 4.0)