2014-09-23 84 views
1

我正在修剪現有的視頻剪輯並將剪輯重新保存在與原始文件相同的位置。然而,當我跑我的應用程序我得到這個錯誤:Videoclip導出錯誤:'無效輸出文件類型'在objective-c

終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,理由是:「無效的輸出文件類型」

我已經找到了建議,但他們要求我改變從outputfiletype AVMediaTypeVideo。我想保留AVMediaTypeVideo,因爲這是原始視頻文件保存的內容。

這是我到目前爲止有:

AVMutableComposition *finalClip = [[AVMutableComposition alloc]init]; 

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; 

NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath]; 

AVURLAsset *videoclip = [AVURLAsset URLAssetWithURL:outputURL options:nil]; 

AVMutableCompositionTrack *finalClipTrack = [finalClip addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 

[finalClipTrack insertTimeRange:CMTimeRangeMake(CMTimeMake((duration*indexNum), 1), CMTimeMake(duration,1)) ofTrack:[[videoclip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; 

NSString *outputPathwe = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"outputwe.mov"]; 

NSURL *outputURLwe = [[NSURL alloc] initFileURLWithPath:outputPathwe]; 

if ([[NSFileManager defaultManager] fileExistsAtPath:outputPathwe]) 
    [[NSFileManager defaultManager] removeItemAtPath:outputPathwe error:nil]; 

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:finalClip presetName:AVAssetExportPresetHighestQuality]; 

exporter.outputFileType = AVMediaTypeVideo; 

exporter.outputURL=outputURLwe; 

[exporter exportAsynchronouslyWithCompletionHandler:^{ 

    dispatch_async(dispatch_get_main_queue(), ^{ 

     [self exportDidFinish:exporter]; 

    }); 
}]; 

我覺得它的東西很容易,我只是缺少。這是我第一次使用AVFoundation,所以任何幫助將不勝感激!

回答

3

AVMediaTypeVideo是「媒體類型」而不是「輸出文件類型」。您的原始視頻具有類型爲AVMediaTypeVideo的曲目。原始視頻的類型不是AVMediaTypeVideo

AVAssetExportSession的outputFileTypeNSString類型的常量。允許的值列在AVFoundation/AVMediaFormat.h中。對於視頻,它們分別是:

  • AVFileTypeQuickTimeMovie
  • AVFileTypeMPEG4
  • AVFileTypeAppleM4V

您必須選擇允許值的一個使用您的AVAssetExportSessionoutputFileType

+0

謝謝你爲我澄清這一點! – kkimble006 2014-09-24 14:33:38