2012-01-09 13 views
7

मैं संयुक्त है 2 कोड हिस्सा एक ठोस टुकड़ा में here पाया (और एक एप्पल डेवलपर Xcode ट्यूटोरियल फ़ाइल के साथ प्रक्रिया सत्यापित)। जब मैं इसे चलाता हूं, हालांकि, मुझे एक त्रुटि मिलती है। यह कहते हैं: "। कार्रवाई पूर्ण नहीं किया जा सकता है (। AVFoundationErrorDomain त्रुटि -11,841)"आईफोन AVErrorInvalidVideoComposition त्रुटि वीडियो पर छवि ओवरले करते समय?

त्रुटि डोमेन = AVFoundationErrorDomain कोड = -11841

किसी भी विचार क्यों यह एक AVErrorInvalidVideoComposition त्रुटि फेंकता है? धन्यवाद! (मैं यहाँ नया हूँ इसलिए यदि आप अधिक जानकारी की आवश्यकता है तो कृपया मुझे बताएं।) अवैध रचनाओं के साथ

NSURL *videoURL = [info valueForKey:UIImagePickerControllerMediaURL]; 

/// UIImage into CALayer 
UIImage *myImage = [UIImage imageNamed:@"Test.png"]; 
CALayer *aLayer = [CALayer layer]; 
aLayer.contents = (id)myImage.CGImage; 

AVURLAsset* url = [AVURLAsset URLAssetWithURL:videoURL options:nil]; 
AVMutableComposition *videoComposition = [[AVMutableComposition alloc] init]; 
NSError *error; 
NSFileManager *fileManager = [NSFileManager defaultManager]; 

AVMutableCompositionTrack *compositionVideoTrack = [videoComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 
AVAssetTrack *clipVideoTrack = [[url tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; 
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [url duration]) ofTrack:clipVideoTrack atTime:kCMTimeZero error:&error]; 

AVMutableVideoComposition* videoComp = [[AVMutableVideoComposition alloc] init]; 
videoComp.renderSize = CGSizeMake(640, 480); 
videoComp.frameDuration = CMTimeMake(1, 30); 
CALayer *parentLayer = [CALayer layer]; 
CALayer *videoLayer = [CALayer layer]; 
parentLayer.frame = CGRectMake(0, 0, videoComp.renderSize.width, videoComp.renderSize.height); 
videoLayer.frame = CGRectMake(0, 0, videoComp.renderSize.width, videoComp.renderSize.height); 
[parentLayer addSublayer:videoLayer]; 
[parentLayer addSublayer:aLayer]; 
videoComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; 


/// instruction 
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30)); 
AVMutableVideoCompositionLayerInstruction* layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack]; 
instruction.layerInstructions = [NSArray arrayWithObject:layerInstruction]; 
videoComp.instructions = [NSArray arrayWithObject: instruction]; 

/// outputs 
NSString *filePath = nil; 
filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
filePath = [filePath stringByAppendingPathComponent:@"temp.mov"]; 
NSLog(@"exporting to: %@", filePath); 
if ([fileManager fileExistsAtPath:filePath]) 
{ 
    BOOL success = [fileManager removeItemAtPath:filePath error:&error]; 
    if (!success) NSLog(@"FM error: %@", [error localizedDescription]); 
} 

/// exporting 
AVAssetExportSession *exporter; 
exporter = [[AVAssetExportSession alloc] initWithAsset:videoComposition presetName:AVAssetExportPresetHighestQuality] ; 
exporter.videoComposition = videoComp; 
exporter.outputURL=[NSURL fileURLWithPath:filePath]; 
exporter.outputFileType=AVFileTypeQuickTimeMovie; 


[exporter exportAsynchronouslyWithCompletionHandler:^(void){ 
    switch (exporter.status) { 
     case AVAssetExportSessionStatusFailed: 
      NSLog(@"exporting failed:%@",exporter.error); 
      break; 
     case AVAssetExportSessionStatusCompleted: 
      NSLog(@"exporting completed"); 
      UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), NULL); 
      break; 
     case AVAssetExportSessionStatusCancelled: 
      NSLog(@"export cancelled"); 
      break; 
    } 
}]; 
+0

क्या आप यह पता लगाने के लिए प्रबंधन करते थे कि समस्या क्या थी? – yonix

+0

गीज़। और मैंने सोचा कि जावा के लंबे परिवर्तनीय नाम थे। – icedwater

उत्तर

9

एक आम समस्या का समय है।

अपने विभिन्न संपत्ति है कि आप के संयोजन कर रहे हैं एक ही लंबाई की जरूरत नहीं है, तो सुनिश्चित करें रचना आपके द्वारा बनाए गए पूरे खंड को शामिल किया गया हैं।

चेक सुनिश्चित करें कि आपके AVMutableVideoCompositionInstruction के timeRange सही है।

संबंधित मुद्दे