Either using a UIImagePicker Controller or AVFoundation I need to capture or record the video where not only camera output but also overlay subviews should be recorded. I have seen lots of example to add the overlay image to camera preview but what i want is not only overlay image or text preview but actual recording of the overlay in the final video output.
// adding Graphical Layer
CALayer *theDonut = [CALayer layer];
theDonut.bounds = CGRectMake(50,50, 150, 150);
theDonut.cornerRadius = 50/2;
theDonut.backgroundColor = [UIColor clearColor].CGColor;
theDonut.borderWidth = 50/5;
theDonut.borderColor = [UIColor orangeColor].CGColor;
// Set up video Preview Layer
videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:capSession];
videoPreviewLayer.frame = videoPreview.bounds;
videoPreviewLayer.backgroundColor = [UIColor blackColor].CGColor;
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
videoPreview.layer.masksToBounds = YES;
[videoPreview.layer addSublayer:videoPreviewLayer];
[videoPreview.layer addSublayer:theDonut];
//7.2 add adding text layer
UIFont *font = [UIFont fontWithName:@"MarkerFelt-Thin" size:40.0];
CGSize maxSize = CGSizeMake(480, 10000.0);
CGSize labelSize = [@"Test Text" sizeWithFont:font constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
CGRect labelFrame = CGRectMake(50.0, 10.0, labelSize.width, labelSize.height);
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.font = font;
label.text = @"Test Text";
label.numberOfLines = 0;
[videoPreview addSubview:label];
// even add button overlay !!!
UIButton *snap = [UIButton buttonWithType:UIButtonTypeCustom];
[snap setImage:[UIImage imageNamed:@"takePic"]
forState:UIControlStateNormal];
[snap addTarget:self
action:@selector(pickerCameraSnap:)
forControlEvents:UIControlEventTouchUpInside];
snap.frame = CGRectMake(74, 370, 178, 37);
[videoPreview addSubview:snap];
// 8) Commit session configuration
// 9) Start running capture session
// ========================================
[capSession commitConfiguration];
[capSession startRunning];
//Make sure video is not recording
[[videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];
This Example is modified from this sample code - It does add text and drawing to the video preview but does not record those in final output file.