公司的项目有视频录制的功能,要求能将自定义视图嵌入到视频中去,下面是效果:
IMG_1602.gif左边进度环是自己定义的内容
代码如下:
///创建摄像头
_videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
_videoCamera.outputImageOrientation = [UIApplication sharedApplication].statusBarOrientation;
//添加时间戳水印和图片水印
UIView *contentView = [[UIView alloc] initWithFrame:self.view.frame];
contentView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy年MM月dd日hh:mm:ss"];
NSDate *currentDate = [NSDate date];
NSString *timeString = [formatter stringFromDate:currentDate];
UILabel *timestampLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 300, 30)];
timestampLabel.text = timeString;
timestampLabel.textColor = [UIColor redColor];
timestampLabel.font = [UIFont systemFontOfSize:20];
[contentView addSubview:timestampLabel];
_progressView = [[JCAnalysisCircleProgress alloc] initWithFrame:CGRectMake(10, 120, 100, 100)];
_progressView.progressWidth = 15;
_progressView.progressColor = [UIColor orangeColor];
_progressView.trackColor = [UIColor whiteColor];
[_progressView setProgress:.5 animated:YES];
[contentView addSubview:_progressView];
///创建水印图形
GPUImageUIElement *uiElement = [[GPUImageUIElement alloc] initWithView:contentView];
///创建滤镜
_filter = [[GPUImageAlphaBlendFilter alloc] init];
((GPUImageAlphaBlendFilter*)_filter).mix = 1;
_filterView = [[GPUImageView alloc] initWithFrame:self.view.frame];
[self.view addSubview: _filterView];
GPUImageFilter *videoFilter = [[GPUImageFilter alloc] init];
[_videoCamera addTarget:videoFilter];
[videoFilter addTarget:_filter];
[uiElement addTarget:_filter];
[_filter addTarget:_filterView];
[_videoCamera startCameraCapture];
///刷新
[videoFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy年MM月dd日hh:mm:ss"];
NSDate *currentDate = [NSDate date];
NSString *timeString = [formatter stringFromDate:currentDate];
timestampLabel.text = timeString;
[uiElement update];
}];
效果不是很好,自定义控件效果不行:
1,进度条的动画没了
2,比较模糊,达不到要求
希望看到的大神给条明路,感激不尽
网友评论