9

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];

// 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.

http://ioscoreframeworks.com/assets/code/DemoCapture.zip

6
  • There is a WWDC video which goes through how to do this and there is associated source code. I can't recall the presentation name now (AVFoundation...) but it should be easy to find. Commented Feb 11, 2013 at 9:39
  • @skinnyTOD : actually have gone through lots of WWDC videos about AVFoundation but couldn't find the simple yet exact code for this particular need hence taking help in StackOverFlow. anyways i'm still surfing through WWDC videos will post solution as soon as i get one. Commented Feb 11, 2013 at 10:04
  • Found one code that does add watermark to the video AVSimpleEditor is a simple AVFoundation based movie editing application which exercises the ... ... demonstrates how they can be used for simple video editing tasks. It also demonstrates how they interact with playback (AVPlayerItem) and export (AVAssetExportSession). The application performs trim, rotate, crop, add music, add watermark and export. This sample is ARC-enabled. developer.apple.com/library/ios/#samplecode/AVSimpleEditoriOS/… Commented Feb 11, 2013 at 10:56
  • Hi, is your text changing or static during the video? I'm looking for a method that will overlay dynamically changing label values. Commented Jul 29, 2013 at 20:30
  • @VanDuTran, did you ever find a way to do dynamically changing labels? I have that challenge now too. Commented Oct 20, 2014 at 17:22

1 Answer 1

0

You can try AVEditdemo application which is included in the WWDC 2010 Sample Code . Unfortunately you need to download all the WWDC 2010 Sample Code to get it (232.6mb). You can get the entire download of all the code here: http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?code=y&source=x&bundleID=20645

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.