最近接觸一個(gè)音頻的項(xiàng)目,之前接觸過,不過都是用系統(tǒng)自帶的去實(shí)現(xiàn),沒有仔細(xì)研究
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),襄垣企業(yè)網(wǎng)站建設(shè),襄垣品牌網(wǎng)站建設(shè),網(wǎng)站定制,襄垣網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,襄垣網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
在網(wǎng)上找到了一個(gè)demo,挺好用,反正效果是實(shí)現(xiàn),非常不錯(cuò)。具體鏈接忘記了。
#pragma mark - 音視頻剪輯,如果是視頻把下面的類型換為AVFileTypeAppleM4V
// assetURL 本地路徑地址
//startTime 開始時(shí)間
//endTime 結(jié)束時(shí)間
//outputPath 裁剪完成后的地址
+ (void)cutAudioVideoResourcePath:(NSURL *)assetURL startTime:(CGFloat)startTime endTime:(CGFloat)endTime complition:(void (^)(NSURL *outputPath,BOOL isSucceed)) completionHandle{
// 素材
AVAsset *asset = [AVAsset assetWithURL:assetURL];
// 導(dǎo)出素材
AVAssetExportSession *exporter = [[AVAssetExportSessionalloc]initWithAsset:assetpresetName:AVAssetExportPresetAppleM4A];
//剪輯(設(shè)置導(dǎo)出的時(shí)間段)
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;
// 合成后的回調(diào)
[exporterexportAsynchronouslyWithCompletionHandler:^{
switch ([exporter status]) {
caseAVAssetExportSessionStatusFailed: {
NSLog(@"合成失?。?@",[[exporter error] description]);
completionHandle(outputPath,NO);
} break;
caseAVAssetExportSessionStatusCancelled: {
completionHandle(outputPath,NO);
} break;
caseAVAssetExportSessionStatusCompleted: {
completionHandle(outputPath,YES);
} break;
default: {
completionHandle(outputPath,NO);
} break;
}
}];
}
#pragma mark - 輸出路徑
+ (NSURL *)exporterPath {
NSInteger nowInter = (long)[[NSDatedate]timeIntervalSince1970];
NSString *fileName = [NSString stringWithFormat:@"output%ld.mp4",(long)nowInter];
NSString *documentsDirectory =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES).lastObject;
NSString *outputFilePath =[documentsDirectory stringByAppendingPathComponent:fileName];
if([[NSFileManagerdefaultManager]fileExistsAtPath:outputFilePath]){
[[NSFileManagerdefaultManager]removeItemAtPath:outputFilePatherror:nil];
}
return [NSURL fileURLWithPath:outputFilePath];
}