I’m working on an app for the ipad 2 that lets the user record video of himself using the device front camera, and then play it back on a video player. I have the overall functionality working, but sometimes, just sometimes my app crashes when I load the view where the video will be played back, because of this:
‘CALayerInvalidGeometry’, reason: ‘CALayer position contains NaN: [nan 11.5]’
I have noticed that the app crashes mostly, but not exclusively, when the recorded clip playing is less than around 15 seconds long.
Anyone have an idea whats going on?s the code that takes care of recording:
Here
-(void)record{
AVCaptureMovieFileOutput *output = [[AVCaptureMovieFileOutput alloc]init];
NSMutableString *videoURL;
if(isRecording){
//here i do some stuff to generate a random system path
[session addOutput:output];
AVCaptureConnection *videoConnection;
[session beginConfiguration];
for ( AVCaptureConnection *connection in [output connections] ) {
for ( AVCaptureInputPort *port in [connection inputPorts] ) {
if ( [[port mediaType] isEqual:AVMediaTypeVideo] ) {
videoConnection = connection;
}
}
}
if([videoConnection isVideoOrientationSupported]){
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
videoConnection.videoMirrored = true;
}
[session commitConfiguration];
[session startRunning];
NSURL *vidURL = [[NSURL alloc]initFileURLWithPath:videoURL];
[output startRecordingToOutputFileURL:vidURL recordingDelegate:self];
NSLog(@"Recording started in %@", videoURL);
[rootRep addObject:videoURL];
[vidURL release];
[videoURL release];
}else{
isRecording = false;
[output stopRecording];
[session removeOutput:output];
[output release];
NSLog(@"Recording stopped");
[recBut setImage:[UIImage imageNamed:@"rec.png"] forState:UIControlStateNormal];
}
}
EDIT: I’ve implemented a method to analize all the captured videos and delete the faulty ones, my app is stable again, but I still wonder why some videos don’t get created well.
I don’t know why exactly the camera doesn’t capture good video files every time, but I’ll show you how you can safely test whether the file works or not. You have to create an AVAsset with the file path you want to test, the AVAsset has a property called ‘playable’, a bool, then you can cycle an array with the addresses of your captured videos asking if the current asset is playable and deleting the corrupted files.