1

i am trying to add time stamp on video that changes every second. I have searched a lot on SO but have not got any perfect solution or way for this

I first tried to add text using this code but with this the string remains static and does not change

CALayer *overlayLayer1 = [CALayer layer];
CATextLayer *subtitle1Text1 = [[CATextLayer alloc] init];
[subtitle1Text1 setFont:@"Helvetica-Bold"];
[subtitle1Text1 setFontSize:36];
[subtitle1Text1 setFrame:CGRectMake(0, 100, size.width, 100)];
dt = [[NSDateFormatter alloc]init];
[dt setDateFormat:@"HH:mm:ss"];
NSDate *date1 = [NSDate dateWithTimeIntervalSinceNow:10];
[subtitle1Text1 setString:[dt stringFromDate:date1]];
[subtitle1Text1 setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text1 setForegroundColor:[[UIColor whiteColor] CGColor]];



[overlayLayer1 addSublayer:subtitle1Text1];
overlayLayer1.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer1 setMasksToBounds:YES];



CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
[parentLayer addSublayer:overlayLayer1];

composition.animationTool = [AVVideoCompositionCoreAnimationTool
                             videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];

than i tried to add animated layer by using following code but some how its not working

CATextLayer *overlayLayer1 = [CATextLayer layer];
 CABasicAnimation *textanim = [CABasicAnimation animationWithKeyPath:@"content"];
textanim.duration = 1.0;
textanim.fromValue = @"Hey";
textanim.toValue = @"Hello";
textanim.beginTime = AVCoreAnimationBeginTimeAtZero;
textanim.removedOnCompletion = NO;
textanim.fillMode = kCAFillModeForwards;
 [overlayLayer1 addAnimation:textanim forKey:@"contentAnimate"]; 
CALayer *parentLayer =    [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
 videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
  [parentLayer addSublayer:videoLayer];
  [parentLayer addSublayer:overlayLayer1];
  [parentLayer addSublayer:overlayLayer2];

  composition.animationTool = [AVVideoCompositionCoreAnimationTool
                               videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];

Can any one please help and let me know what am i doing wrong? or is there any way to achieve what i want ( To add time stamp on video).

EDIT

I am able to export video , My issue here is that on that exported video i want to add text that changes with time which i am not getting with above code.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
  • http://stackoverflow.com/questions/22337019/get-time-stamp-location-of-ios-video – Rushabh May 30 '14 at 10:07
  • Thanks for your time , this question shows how to get date and time of video. What i want to do is to add a date time layer on a video. So when user later plays that video he can see date on video. Hope i am able to explain my question. – Bhumit Mehta May 30 '14 at 10:25
  • There is no straightforward way to achieve this. – TEJAS PATELIA Sep 16 '15 at 10:03

0 Answers0