在我的应用程序中有录制视频的功能,我想在录制的视频上添加时间和日期的详细信息。
只是我可以在它在应用程序中运行时添加,但我想做的是如果我在照片应用程序中导出该视频或通过电子邮件发送该视频,那么日期和时间也应该在那里。
我检查了这个来自苹果的示例代码,但在这个文本中可以是静态的,将始终保持不变。
任何人都可以指导我或任何链接吗?如何在视频上添加时间戳细节..
感谢您的帮助。
最佳答案
您可以使用 GPUImage Class作者 Brad Larson,它允许您根据需要向图像和视频添加滤镜。我最近只是在我的一个项目中实现了您要求的确切内容。
我所做的是将 UILabel 用作 GPUImageUIElement
并将其添加到 GPUImageNormalBlendFilter
。我在每次回调时都更新了标签文本,效果非常好。
代码如下:
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];
}];
我知道这个问题很老,但可能会对某人有所帮助,因为我花了一段时间才找到这个问题。
关于iphone - 在录制的视频上添加日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14894324/