Add Date and time on recorded video

断了今生、忘了曾经 提交于 2020-01-01 00:46:10

问题


In my application there feature of recording video, I want to add time and date details on the recorded video.

Simply i can add while it running within the app but what i want to do is If i export that video in Photo app or email that video, than also date and time should be there.

I checked this sample code from apple but in this text can be static that will remain same all time.

AVSimpleEditor

Can any one guide me or any link ? How to add time stamp detail on video..

Thanks for any help.


回答1:


You can use GPUImage Class by Brad Larson , It allows you to add filter to image and video as per your requirment . I just implement the exact thing that you asked for in one of my projects recently.

What i did was use UILabel as GPUImageUIElement and added it to 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 question is old but might help someone as it took me a while to find this.




回答2:


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

If you use a CATextLayer you can animate the string property.



来源:https://stackoverflow.com/questions/14894324/add-date-and-time-on-recorded-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!