I have a recording application where the user can click the βrecordβ button to start / stop recording. I achieve this with a baseline GPUImageVideoCamerawith the output set to GPUImageViewas well GPUImageMovieWriter.
50% of the time, the recorded clip ends with a pair (or one) of a black frame at both ends, sometimes both. The implementation is pretty simple, but it's all the same.
gpuImageView = [[GPUImageView alloc] initWithFrame:cameraView.frame];
gpuImageView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
[cameraView addSubview:gpuImageView];
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:(usingBackCamera) ? AVCaptureDevicePositionBack : AVCaptureDevicePositionFront];
[videoCamera addTarget:gpuImageView];
[videoCamera addTarget:movieWriter];
videoCamera.audioEncodingTarget = movieWriter;
[videoCamera startCameraCapture];
double delayToStartRecording = 0.5;
dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Start recording");
[movieWriter startRecording];
});
And then stop recording as follows (while the live camera continues to display on GPUImageView.
[movieWriter finishRecording]
Has anyone else experienced this and / or found a solution to avoid black frames? I can not pause / resume camera capture to ensure smooth operation with the user.