Add date and time for recorded video

My application has a video recording function, I want to add time and date data to the recorded video.

I can simply add it when it works in the application, but what I want to do is if I export this video to the Photos application or send this video by email, as well as the date and time should be there.

I checked this sample code from apple, but in this text it may be static, which will remain the same all the time.

AVSimpleEditor

Can someone direct me or the link? How to add a timestamp to a video ..

Thanks for any help.

+3
objective-c iphone video-recording
source share
2 answers

You can use the GPUImage class from Brad Larson, it allows you to add a filter to the image and video according to your requirement. I just implement what you asked for in one of my projects recently.

I used UILabel as a GPUImageUIElement and added it to the GPUImageNormalBlendFilter . I updated the label text with every callback and it worked like a charm.

Here is the code:

 filterView = [[GPUImageView alloc] initWithFrame:self.videoRecordView.frame]; videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920,1080)]; [self.view addSubview:filterView]; movieWriter.encodingLiveVideo = YES; movieWriter.encodingLiveVideo = YES; videoCamera.audioEncodingTarget = movieWriter; GPUImageNormalBlendFilter *blendFilter1 = [[GPUImageNormalBlendFilter alloc] init]; UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 635, 768.0f, 50.0f)]; timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; timeLabel.textAlignment = NSTextAlignmentCenter; timeLabel.backgroundColor = [UIColor clearColor]; timeLabel.textColor = [UIColor whiteColor]; uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel]; [uiElementInput addTarget:blendFilter1]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"MMMM dd, yyyy hh : mm : ss a"]; [blendFilter1 addTarget:filterView]; [blendFilter1 addTarget:movieWriter]; [videoCamera addTarget:blendFilter1]; __unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput; [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){ timeLabel.textColor =[UIColor whiteColor]; float sizefont =[[[NSUserDefaults standardUserDefaults]objectForKey:KfontSize] floatValue]; timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(sizefont)? sizefont:30]; NSDate * originalDate = [NSDate dateWithTimeIntervalSinceNow:interval]; NSString *timeString=[dateFormatter stringFromDate:originalDate]; timeLabel.text = [NSString stringWithFormat:@"%@", timeString]; [weakUIElementInput update]; }]; 

I know the question is old, but it might help someone, since it took me a while to find this.

+2
source share

The pattern you linked shows you how to get 90% of the way. The final step is to look at the docs for AVVideoCompositionCoreAnimationTool . This class allows you to add any core animation to the video. How do you do this by adding animation to CALayer .

If you use CATextLayer, you can animate a row property.

+1
source share

Source: https://habr.com/ru/post/651304/


All Articles