2014-09-23 4 views
1

기존 비디오 클립을 잘라내어 원본 파일과 동일한 위치에 클립을 다시 저장하려고합니다. 때문에 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료Videoclip 내보내기 오류 : objective-c의 '잘못된 출력 파일 형식'

가, 이유 : '잘못된 출력 파일 형식이'

내가 권장 사항을 발견하지만 그들은에서 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에 나열됩니다. 비디오의 경우, 그들은 : 당신은 당신의 AVAssetExportSessionoutputFileType에 사용할 허용 된 값 중 하나를 선택해야

  • AVFileTypeMPEG4
  • AVFileTypeAppleM4V
    • AVFileTypeQuickTimeMovie.

    +0

    나를 명확히 해 주셔서 감사합니다. – kkimble006