获取手机本地视频,并加音频mp3合成
有疑问加QQ903040553
pod 'ZLPhotoBrowser'
#pragma mark 选择视频
- (void)sentViode{
ZLPhotoActionSheet *ac = [[ZLPhotoActionSheet alloc] init];
//相册参数配置,configuration有默认值,可直接使用并对其属性进行修改
ac.configuration.maxSelectCount = 1;
ac.configuration.maxPreviewCount = 10;
ac.configuration.allowSelectImage = NO;//是否允许选择照片
ac.configuration.allowTakePhotoInLibrary = NO;// 是否允许相册内部拍照
ac.configuration.allowSelectOriginal = NO;//是否允许选择原图
ac.configuration.allowEditVideo = YES;//是否允许编辑视频
ac.configuration.maxEditVideoTime = 30;//大于30秒才可以编辑
ac.configuration.maxVideoDuration = 30;//允许选择300s
// ac.configuration.editAfterSelectThumbnailImage = YES;//在小图界面选择 图片/视频 后直接进入编辑界面,默认NO
//如调用的方法无sender参数,则该参数必传
ac.sender=self;
// //选择回调
[acsetSelectImageBlock:^(NSArray *_Nonnullimages,NSArray *_Nonnullassets,BOOLisOriginal) {
//your codes
PHAsset*itme = [assetsobjectAtIndex:0];
//获取视频
[[PHImageManagerdefaultManager]requestAVAssetForVideo:itmeoptions:nilresultHandler:^(AVAsset*_Nullableasset,AVAudioMix*_NullableaudioMix,NSDictionary*_Nullableinfo) {
NSString * url = [[[info objectForKey:@"PHImageFileSandboxExtensionTokenKey"]componentsSeparatedByString:@";"] lastObject];
url = [@"file://"stringByAppendingString:url];
// NSString *path=[[NSBundle mainBundle] pathForResource:@"123" ofType:@"txt"];
NSURL*url2 = [NSURLURLWithString:url];
[selfhead:url2];
// NSData *data = [NSData dataWithContentsOfURL: exportSession.outputURL];
// _data = data;
// [self sendVideo];
_playUrl= url2;
[selfplayVideo];
// NSData *data = [NSData dataWithContentsOfURL:url2];
// _data = data;
// [self sendVideo];
// _playUrl = url2;
// [self playVideo];
// NSURL* videoURL = [NSURL URLWithString:url];
// [self readingFile];
// [self VideoAddMusic:videoURL];
}];
}];
//调用相册
[acshowPhotoLibraryWithSender:self];
}
//合成音频
//- (void)VideoAddMusic:(NSURL *)url{
// // NSURL * videoUrl= [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ARShoot" ofType:@"mov"]];
// NSURL *videoUrl = url;
// // NSURL * musicUrl= [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"DangerInLovingYou" ofType:@"mp3"]];
// /**
// 音视频合成
//
// @param assetURL 原始视频路径
// @param BGMPath 背景音乐路径
// @param needOriginalVoice 是否添加原视频的声音
// @param videoVolume 视频音量
// @param BGMVolume 背景音乐音量
// @param completionHandle 合成后的回调
// */
// [EditAudioVideo editVideoSynthesizeVieoPath:videoUrl BGMPath:nil needOriginalVoice:NO videoVolume:9 BGMVolume:0 complition:^(NSURL *outputPath, BOOL isSucceed) {
// //
// NSLog(@"outputPath=======%@",outputPath);
// NSString *str1 = [outputPath absoluteString];
// NSLog(@"str1======%@",str1);
// [self readingFile];
// dispatch_async(dispatch_get_main_queue(), ^{
// _playUrl = outputPath;
// [self playVideo];
// // FinshViewController *finshVC = [FinshViewController new];
// // finshVC.playURL = outputPath;
// // [self presentViewController:finshVC animated:YES completion:nil];
// // [BMToast makeText:@"我的视频上传成功了"];
// });
//
// }];
//
//}
//// 读取写入的文件
//
//- (void)readingFile
//{
// // 读字符串
// // 获取路径
// NSArray *documentsPathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSString *documentsPath = [documentsPathArr lastObject];
// //读data
// NSString *dataPath = [documentsPath stringByAppendingPathComponent:@"FLOutputFile.mp4"];
// // 读取data
// NSData *data = [NSData dataWithContentsOfFile:dataPath];
// NSLog(@"二进制流=========%@", data);
// // 将data转化成字符串
// NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// // NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// // NSLog(@"%@", dataStr);
//}