您好,登錄后才能下訂單哦!
最近接觸一個音頻的項目,之前接觸過,不過都是用系統自帶的去實現,沒有仔細研究
在網上找到了一個demo,挺好用,反正效果是實現,非常不錯。具體鏈接忘記了。
#pragma mark - 音視頻剪輯,如果是視頻把下面的類型換為AVFileTypeAppleM4V
// assetURL 本地路徑地址
//startTime 開始時間
//endTime 結束時間
//outputPath 裁剪完成后的地址
+ (void)cutAudioVideoResourcePath:(NSURL *)assetURL startTime:(CGFloat)startTime endTime:(CGFloat)endTime complition:(void (^)(NSURL *outputPath,BOOL isSucceed)) completionHandle{
// 素材
AVAsset *asset = [AVAsset assetWithURL:assetURL];
// 導出素材
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
//剪輯(設置導出的時間段)
CMTime start = CMTimeMakeWithSeconds(startTime, asset.duration.timescale);
CMTime duration = CMTimeMakeWithSeconds(endTime - startTime,asset.duration.timescale);
exporter.timeRange = CMTimeRangeMake(start, duration);
// 輸出路徑
NSURL *outputPath = [self exporterPath];
exporter.outputURL = [self exporterPath];
// 輸出格式
exporter.outputFileType = AVFileTypeAppleM4A;
exporter.shouldOptimizeForNetworkUse= YES;
// 合成后的回調
[exporter exportAsynchronouslyWithCompletionHandler:^{
switch ([exporter status]) {
case AVAssetExportSessionStatusFailed: {
NSLog(@"合成失敗:%@",[[exporter error] description]);
completionHandle(outputPath,NO);
} break;
case AVAssetExportSessionStatusCancelled: {
completionHandle(outputPath,NO);
} break;
case AVAssetExportSessionStatusCompleted: {
completionHandle(outputPath,YES);
} break;
default: {
completionHandle(outputPath,NO);
} break;
}
}];
}
#pragma mark - 輸出路徑
+ (NSURL *)exporterPath {
NSInteger nowInter = (long)[[NSDate date] timeIntervalSince1970];
NSString *fileName = [NSString stringWithFormat:@"output%ld.mp4",(long)nowInter];
NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
NSString *outputFilePath =[documentsDirectory stringByAppendingPathComponent:fileName];
if([[NSFileManager defaultManager]fileExistsAtPath:outputFilePath]){
[[NSFileManager defaultManager]removeItemAtPath:outputFilePath error:nil];
}
return [NSURL fileURLWithPath:outputFilePath];
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。