阿里云短视频IOS-SDK转场

  • 转场的相关接口在VideoProducer.framewrok中RMVPMediaTrack.h头文件。

添加基础转场

  • 添加基础转场,目前支持淡入、闪黑、闪白、模糊、横滑、纵滑。添加转场,需要传入媒体轨道上插入点(即,片段相应位置,这里可参考转场UI逻辑)
  • 代码示例如下:

//创建转场效果实例,这里以读取本地配置文件为例NSString *name = [NSString stringWithFormat:@"bundle/%@.zip",转场唯一签名]; NSString *path = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:name]; BOOL isExist = [[NSFileManager defaultManager] fileExistsAtPath:path]; //解压 if (isExist) { NSString *destPath = [self localPath]; destPath = [destPath stringByAppendingPathComponent:item.sign]; BOOL bSucess = [self unzipStickerPackage:path destPath:destPath]; if (bSucess) { // 读取json文件 NSString *jsonPath = [destPath stringByAppendingPathComponent:@"transition_config.json"]; BOOL isJsonExist = [[NSFileManager defaultManager] fileExistsAtPath:jsonPath]; if (isJsonExist) { NSData *data=[NSData dataWithContentsOfFile:jsonPath]; NSError *error; NSDictionary *jsonDict =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; if(jsonDict != nil && jsonDict.count > 0) {NSString *library_name= @"library_name";NSString *vertex_function= @"vertex_function";NSString *fragment_function = @"fragment_function";NSString *durationKey= @"duration"; NSString *library = [jsonDict objectForKey:library_name];NSString *libraryPath = [destPath stringByAppendingPathComponent:library]; if (![[NSFileManager defaultManager] fileExistsAtPath:libraryPath]) {return nil;} NSString *vertexShaderName = [jsonDict objectForKey:vertex_function];NSString *fragmentShaderName = [jsonDict objectForKey:fragment_function];CGFloat defaultDuration = 0.5 * 1000;CGFloat duration = [jsonDict hk_floatForKey:durationKey];if (duration <0.01) {duration = defaultDuration;}//创建转场效果实例RMVPMediaVideoTransitionItem *mediaItem = [[RMVPMediaVideoTransitionItem alloc] initWithType:RMVPMediaVideoTransitionItemTypeDual transitionType:RMVPMediaVideoTransitionItemTypeTransitionTypeDefault libraryPath:libraryPath vertexFunctionName:vertexShaderName fragmentFunctionName:fragmentShaderName];mediaItem.duration = CMTimeMakeWithSeconds(duration / 1000, NSEC_PER_SEC);mediaItem.transitionId = item.transition_id; } } } }//删除原有转场效果[self.videoTrack removeTransitionItemAtIndex:index];//绑定最新转场效果[self.videoTrack bindTransitionItem:mediaItem atIndex:index];