3

在我的应用程序中有录制视频的功能,我想在录制的视频上添加时间和日期详细信息。

简单地说,我可以在它在应用程序中运行时添加,但我想做的是如果我在照片应用程序中导出该视频或通过电子邮件发送该视频,那么日期和时间也应该在那里。

我从苹果检查了这个示例代码,但在这个文本中可以是静态的,将始终保持不变。

AVSimpleEditor

任何人都可以指导我或任何链接吗?如何在视频上添加时间戳细节..

谢谢你的帮助。

4

2 回答 2

2

您可以使用Brad Larson 的GPUImage 类,它允许您根据需要为图像和视频添加过滤器。我只是实现了您最近在我的一个项目中要求的确切内容。

我所做的是使用 UILabelGPUImageUIElement并将其添加到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];
}];

我知道问题很旧,但可能会对某人有所帮助,因为我花了一段时间才找到它。

于 2014-09-15T10:57:21.043 回答
1

您链接的示例向您展示了如何获得 90% 的方法。最后一步是查看AVVideoCompositionCoreAnimationTool的文档。此类允许您将任何核心动画添加到视频中。你如何做到这一点是通过将动画添加到CALayer

如果您使用 CATextLayer,您可以为字符串属性设置动画。

于 2013-02-15T12:37:43.477 回答