初始化贴纸添加的实例:
self.filterProcessor = [[TuSDKFilterProcessor alloc] initWithFormatType:kCVPixelFormatType_32BGRA isOriginalOrientation:NO];
self.filterProcessor.outputPixelFormatType = lsqFormatTypeBGRA;
// TuSDKFilterProcessor 默认不启用贴纸,这里需要主动启用贴纸功能
[self.filterProcessor setEnableLiveSticker:YES];
self.stickerView = [[StickerScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 300)];
self.stickerView.stickerDelegate = self;
self.stickerView.cameraStickerType = lsqCameraStickersTypeSquare;
选择贴纸。在贴纸选择的回调,处理贴纸:
(void)clickStickerViewWith:(TuSDKPFStickerGroup *)stickGroup {
if (!stickGroup) {
// 为nil时 移除已有贴纸组;
[_filterProcessor removeMediaEffectsWithType:TuSDKMediaEffectDataTypeSticker];
} else {
// 选中了某个贴纸,将其添加到 filterProcessor 中
[self.filterProcessor showGroupSticker:stickGroup];
}
}
贴纸选择完成之后,我们可以将贴纸应用到视频录制中。和滤镜处理类似,在短视频拍摄的视频数据回调中,应用贴纸:
- (CVPixelBufferRef)shortVideoRecorder:(PLShortVideoRecorder *)recorder cameraSourceDidGetPixelBuffer:(CVPixelBufferRef)pixelBuffer {
// 进行滤镜处理
pixelBuffer = [self.filter process:pixelBuffer];
// TuSDK 进行贴纸处理
pixelBuffer = [self.filterProcessor syncProcessPixelBuffer:pixelBuffer];
[self.filterProcessor destroyFrameData];
return pixelBuffer;
}
2.7 分段变速拍摄
如果想拍摄的视频以快速或者慢速播放,可以设置拍摄速率:
self.shortVideoRecorder.recoderRate = PLSVideoRecoderRateTopFast;
2.8 结束拍摄
如果要结束某一段视频的录制,可以调用停止录制方法:
[self.shortVideoRecorder stopRecording];
调用停止录制之后,保存的视频会通过录制完成回调返回出来:
- (void)shortVideoRecorder:(PLShortVideoRecorder *)recorder didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL fileDuration:(CGFloat)fileDuration totalDuration:(CGFloat)totalDuration {
}
停止音视频采集。如果不再需要拍摄视频,可以调用停止采集方法来结束拍摄:
[self.shortVideoRecorder stopCaptureSession];
**
视频编辑
**
3.1 开始编辑
编辑类 PLShortVideoEditor 支持渲染音视频、水印、滤镜、背景音乐、MV 特效等功能
初始化和启动编辑:
self.shortVideoEditor = [[PLShortVideoEditor alloc] initWithAsset:asset videoSize:CGSizeZero];
self.shortVideoEditor.delegate = self;
self.shortVideoEditor.loopEnabled = YES;
[self.view addSubview:self.shortVideoEditor.preview];
[self.shortVideoEditor startEditing];
3.2 添加背景音乐
添加背景音乐
[self.shortVideoEditor addMusic:musicURL timeRange:timeRange volume:1.0];
调节背景音乐音量
[self.shortVideoEditor updateMusic:timeRange volume:0.5];
3.3 添加文字特效
添加文字的逻辑和添加贴纸使用的是同一个逻辑,用户可以使用七牛短视频 Demo 中已经包装好的添加文字、贴纸的类 PLSStickerView:
PLSStickerView *stickerView = [[PLSStickerView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
// 以字典的形式,保存 stickerView 信息
NSMutableDictionary *stickerSettings = [[NSMutableDictionary alloc] init];
stickerSettings[PLSStickerKey] = stickerView;
stickerSettings[PLSSizeKey] = [NSValue valueWithCGSize:viewSize];
stickerSettings[PLSPointKey] = [NSValue valueWithCGPoint:viewPoint];
CGFloat rotation = atan2f(transform.b, transform.a);
rotation = rotation * (180 / M_PI);
stickerSettings[PLSRotationKey] = [NSNumber numberWithFloat:rotation];
[self.stickerSettingsArray addObject:stickerSettings];
3.4 添加抖音特效
七牛短视频 SDK 没有集成特效,但是和人脸贴纸一样,可以轻松的接入第三方的特效。下面我们还以添加 涂图 的特效为例,演示特效的添加方式
首先,初始化特效添加器:
self.filterProcessor = [[TuSDKFilterProcessor alloc] initWithFormatType:kCVPixelFormatType_32BGRA isOriginalOrientation:isOriginalOrientation];
self.filterProcessor.delegate = self;
self.filterProcessor.mediaEffectDelegate = self;
// 默认关闭动态贴纸功能,即关闭人脸识别功能
self.filterProcessor.enableLiveSticker = NO;
添加灵魂出窍特效:
TuSDKMediaSceneEffectData *effectData = [[TuSDKMediaSceneEffectData alloc] initWithEffectsCode:@“LiveSoulOut01”];
effectData.atTimeRange = [TuSDKTimeRange makeTimeRangeWithStart:kCMTimeZero end:CMTimeMake(INTMAX_MAX, 1)];
[self.filterProcessor addMediaEffect:effectData];
应用特效。在短视频编辑视频数据回调里面,将特效应用,以便预览特效效果:
- (CVPixelBufferRef)shortVideoEditor:(PLShortVideoEditor *)editor didGetOriginPixelBuffer:(CVPixelBufferRef)pixelBuffer timestamp:(CMTime)timestamp {
// 应用特效
pixelBuffer = [self.filterProcessor syncProcessPixelBuffer:pixelBuffer frameTime:timestamp];
[self.filterProcessor destroyFrameData];
return pixelBuffer;
}
视频导出
上面我们的短视频编辑就完成了,现在我们将编辑的视频使用 PLSAVAssetExportSession
导出来保存到本地相册
初始化视频导出器:
NSMutableDictionary *outputSettings = [[NSMutableDictionary alloc] init];
NSMutableDictionary *movieSettings = [[NSMutableDictionary alloc] init];
NSMutableDictionary *backgroundAudioSettings = [NSMutableDictionary alloc] init];
NSMutableArray *stickerSettingsArray = [[NSMutableArray alloc] init];
NSMutableArray *audioSettingsArray = [[NSMutableArray alloc] init];
// 将导出信息设置到 outputSettings 中
// do setting…
AVAsset *asset = movieSettings[PLSAssetKey];
PLSAVAssetExportSession *exportSession = [[PLSAVAssetExportSession alloc] initWithAsset:asset];
exportSession.outputFileType = PLSFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputSettings = self.outputSettings;
exportSession.delegate = self;
exportSession.isExportMovieToPhotosAlbum = YES;
设置导出视频相关 block:
__weak typeof(self) weakSelf = self;
[exportSession setCompletionBlock:^(NSURL *url) {
NSLog(@“视频已保存到相册中”);
}];
[exportSession setFailureBlock:^(NSError *error) {
NSLog(@“导出视频失败”);
}];
[exportSession setProcessingBlock:^(float progress) {
NSLog(@“视频导出完成百分比: %f”, process);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
尾声
在我的博客上很多朋友都在给我留言,需要一些系统的面试高频题目。之前说过我的复习范围无非是个人技术博客还有整理的笔记,考虑到笔记是手写版不利于保存,所以打算重新整理并放到网上,时间原因这里先列出面试问题,题解详见:
展示学习笔记
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
39)]
展示学习笔记
[外链图片转存中…(img-j0UuQbNA-1712780335939)]
[外链图片转存中…(img-FjliYnKR-1712780335940)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-s8GzSi0J-1712780335940)]