ios 開(kāi)發(fā) 視頻格式轉(zhuǎn)換、mov轉(zhuǎn)MP4

? ? ?NSURL*videoUrl = mediaURL;

?(格式) media = @"file:///private/var/mobile/Containers/Data/Application/0541F390-33AE-4910-BFC3-30819DF8317C/tmp/0A809814-E89A-42D9-9760-F9E0FDDA9B4A.MOV"

? ? ? ? ? ? ? ? /**

?? ? ? ? ? ? ? ? *? mov格式轉(zhuǎn)mp4格式

?? ? ? ? ? ? ? ? */

? ? ? ? ? ? ?AVURLAsset*avAsset = [AVURLAssetURLAssetWithURL:[NSURLfileURLWithPath:videoUrl.absoluteString]options:nil];

? ? AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];

? ? NSArray*compatiblePresets = [AVAssetExportSessionexportPresetsCompatibleWithAsset:avAsset];

? ? ? ? ? ? ? ? /**

?? ? ? ? ? ? ? ? AVAssetExportPresetMediumQuality 表示視頻的轉(zhuǎn)換質(zhì)量,

?? ? ? ? ? ? ? ? */

? ? ? ? ? ? ? ? if([compatiblePresetscontainsObject:AVAssetExportPresetMediumQuality]) {


? ? ? ? ? ? ? ? ? ? NSURL*newVideoUrl ;//一般.mp4

? ? ? ? ? ? ? ? ? ? NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用時(shí)間給文件全名,以免重復(fù),在測(cè)試的時(shí)候其實(shí)可以判斷文件是否存在若存在,則刪除,重新生成文件即可

? ? ? ? ? ? ? ? ? ? [formatersetDateFormat:@"yyyy-MM-dd-HH:mm:ss"];

? ? ? ? ? ? ? ? ? ? newVideoUrl = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]]] ;


? ? ? ? ? ? ? ? ? ? exportSession.outputURL= newVideoUrl;


? ? ? ? ? ? ? ? ? ? //要轉(zhuǎn)換的格式,這里使用 MP4

? ? ? ? ? ? ? ? ? ? exportSession.outputFileType=AVFileTypeMPEG4;


? ? ? ? ? ? ? ? ? ? //轉(zhuǎn)換的數(shù)據(jù)是否對(duì)網(wǎng)絡(luò)使用優(yōu)化

? ? ? ? ? ? ? ? ? ? exportSession.shouldOptimizeForNetworkUse=YES;


? ? ? ? ? ? ? ? ? ? //異步處理開(kāi)始轉(zhuǎn)換

? ? ? ? ? ? ? ? ? ? [exportSessionexportAsynchronouslyWithCompletionHandler:^(void)


?? ? ? ? ? ? ? ? ? ? {

?? ? ? ? ? ? ? ? ? ? ? ? //轉(zhuǎn)換狀態(tài)監(jiān)控

?? ? ? ? ? ? ? ? ? ? ? ? switch(exportSession.status) {

?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusUnknown:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusUnknown");

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;


?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusWaiting:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusWaiting");

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;


?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusExporting:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusExporting");

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;

?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusFailed:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusFailed");

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;

?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusCancelled:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusCancelled");

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;


?? ? ? ? ? ? ? ? ? ? ? ? ? ? case AVAssetExportSessionStatusCompleted:

?? ? ? ? ? ? ? ? ? ? ? ? ? ? {

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //轉(zhuǎn)換完成

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"AVAssetExportSessionStatusCompleted");




?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;


?? ? ? ? ? ? ? ? ? ? ? ? ? ? }

?? ? ? ? ? ? ? ? ? ? ? ? }


?? ? ? ? ? ? ? ? ? ? }];


? ? ? ? ? ? ? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容