转场
更新时间:2020-12-11
- 转场的相关接口在VideoProducer.framewrok中RMVPMediaTrack.h头文件。
添加基础转场
- 添加基础转场,目前支持淡入、闪黑、闪白、模糊、横滑、纵滑。添加转场,需要传入媒体轨道上插入点(即,片段相应位置,这里可参考转场UI逻辑)
- 代码示例如下:
Plain Text
1 //创建转场效果实例,这里以读取本地配置文件为例
2 NSString *name = [NSString stringWithFormat:@"bundle/%@.zip",转场唯一签名];
3
4 NSString *path = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:name];
5
6 BOOL isExist = [[NSFileManager defaultManager] fileExistsAtPath:path];
7
8 //解压
9
10 if (isExist) {
11
12 NSString *destPath = [self localPath];
13
14 destPath = [destPath stringByAppendingPathComponent:item.sign];
15
16 BOOL bSucess = [self unzipStickerPackage:path destPath:destPath];
17
18 if (bSucess) {
19
20 // 读取json文件
21
22 NSString *jsonPath = [destPath stringByAppendingPathComponent:@"transition_config.json"];
23
24 BOOL isJsonExist = [[NSFileManager defaultManager] fileExistsAtPath:jsonPath];
25
26 if (isJsonExist) {
27
28 NSData *data=[NSData dataWithContentsOfFile:jsonPath];
29
30 NSError *error;
31
32 NSDictionary *jsonDict =[NSJSONSerialization JSONObjectWithData:data
33
34 options:NSJSONReadingAllowFragments
35
36 error:&error];
37
38 if(jsonDict != nil && jsonDict.count > 0) {
39
40 NSString *library_name = @"library_name";
41
42 NSString *vertex_function = @"vertex_function";
43
44 NSString *fragment_function = @"fragment_function";
45
46 NSString *durationKey = @"duration";
47
48 NSString *library = [jsonDict objectForKey:library_name];
49
50 NSString *libraryPath = [destPath stringByAppendingPathComponent:library];
51
52 if (![[NSFileManager defaultManager] fileExistsAtPath:libraryPath]) {
53
54 return nil;
55
56 }
57
58 NSString *vertexShaderName = [jsonDict objectForKey:vertex_function];
59
60 NSString *fragmentShaderName = [jsonDict objectForKey:fragment_function];
61
62 CGFloat defaultDuration = 0.5 * 1000;
63
64 CGFloat duration = [jsonDict hk_floatForKey:durationKey];
65
66 if (duration <0.01) {
67
68 duration = defaultDuration;
69
70 }
71 //创建转场效果实例
72 RMVPMediaVideoTransitionItem *mediaItem = [[RMVPMediaVideoTransitionItem alloc] initWithType:RMVPMediaVideoTransitionItemTypeDual transitionType:RMVPMediaVideoTransitionItemTypeTransitionTypeDefault libraryPath:libraryPath vertexFunctionName:vertexShaderName fragmentFunctionName:fragmentShaderName];
73
74 mediaItem.duration = CMTimeMakeWithSeconds(duration / 1000, NSEC_PER_SEC);
75
76 mediaItem.transitionId = item.transition_id;
77
78 }
79
80 }
81
82 }
83
84 }
85
86
87 //删除原有转场效果
88 [self.videoTrack removeTransitionItemAtIndex:index];
89
90
91 //绑定最新转场效果
92 [self.videoTrack bindTransitionItem:mediaItem atIndex:index];