合成
更新时间:2020-12-11
- 合成模块负责将编辑后的视频导出成本地视频
导出预览视频
- 导出预览视频,将媒体轨道中心的所管理的视频、音频、字幕导出本地,默认是.mp4文件。导出时,需要暂停预览
- 代码示例如下:
//暂停预览
[self.previewer pausePreview];
NSDate *currentDate = [NSDate date];
double timeStamp = [currentDate timeIntervalSince1970];
NSString *videoName = [[NSString stringWithFormat:@"%f",timeStamp] stringByAppendingString:@".mp4"];
NSString *documentsDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *videoDirPath = [documentsDirPath stringByAppendingPathComponent:@"video_export"];
[[NSFileManager defaultManager] createDirectoryAtPath:videoDirPath withIntermediateDirectories:YES attributes:nil error:nil];
NSURL *documentsDirUrl = [NSURL fileURLWithPath:videoDirPath isDirectory:YES];
NSURL *output = [NSURL URLWithString:name relativeToURL:documentsDirUrl];
RMVPVideoEditConfig *config = [RMVPMediaConfigManager defaultEditConfig];
self.mediaExporter = [[RMVPMediaExporter alloc] initWithMediaTracksCenter:self.videoTrack outputURL:output config:config];
[self.mediaExporter startExportWithProgress:^(CGFloat progress) {
NSLog(@"media - exporter - progress %f", progress);
} completion:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"media - exporter - success");
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:output];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (success) {
[self.previewer resumePreview];
}
}];
});
} else {
}
}];