2011-02-17 17 views
8

मैं अपने चित्र अनुक्रम को एक क्विकटाइम वीडियो में निर्यात करने का सही तरीका ढूंढ रहा हूं।कोरएनीमेशन, AVFoundation और वीडियो निर्यात करने की क्षमता

मुझे पता है कि एवी फाउंडेशन में वीडियो विलय करने या पुन: संयोजित करने की क्षमता है और ऑडियो ट्रैक को एक वीडियो एसेट बनाने की क्षमता भी है।

अब ... मेरा लक्ष्य थोड़ा अलग है। मैं खरोंच से एक वीडियो बनाना चाहता हूँ। मेरे पास UIImage का एक सेट है और मुझे उन सभी को एक ही वीडियो में प्रस्तुत करने की आवश्यकता है। मैंने एवी फाउंडेशन के बारे में सभी ऐप्पल दस्तावेज़ीकरण को पढ़ा और मुझे AVVideoCompositionCoreAnimationTool क्लास मिला जिसमें कोरएनीमेशन लेने और इसे वीडियो के रूप में पुनः नामित करने की क्षमता है। मैंने ऐप्पल द्वारा प्रदान की गई AVEditDemo प्रोजेक्ट की भी जांच की लेकिन कुछ ऐसा प्रोजेक्ट पर काम नहीं कर रहा है।

यहाँ मेरी कदम:

1) मैं CoreAnimation लेयर

CALayer *animationLayer = [CALayer layer]; 
[animationLayer setFrame:CGRectMake(0, 0, 1024, 768)]; 

CALayer *backgroundLayer = [CALayer layer]; 
[backgroundLayer setFrame:animationLayer.frame]; 
[backgroundLayer setBackgroundColor:[UIColor blackColor].CGColor]; 

CALayer *anImageLayer = [CALayer layer]; 
[anImageLayer setFrame:animationLayer.frame]; 

CAKeyframeAnimation *changeImageAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"]; 
[changeImageAnimation setDelegate:self]; 
changeImageAnimation.duration = [[albumSettings transitionTime] floatValue] * [uiImagesArray count]; 
changeImageAnimation.repeatCount = 1; 
changeImageAnimation.values = [NSArray arrayWithArray:uiImagesArray]; 
changeImageAnimation.removedOnCompletion = YES; 
[anImageLayer addAnimation:changeImageAnimation forKey:nil]; 

[animationLayer addSublayer:anImageLayer]; 

2) से मैं AVComposition

AVMutableComposition *composition = [AVMutableComposition composition]; 
composition.naturalSize = CGSizeMake(1024, 768); 

CALayer *wrapLayer = [CALayer layer]; 
wrapLayer.frame = CGRectMake(0, 0, 1024, 768); 
CALayer *videoLayer = [CALayer layer]; 
videoLayer.frame = CGRectMake(0, 0, 1024, 768); 
[wrapLayer addSublayer:animationLayer]; 
[wrapLayer addSublayer:videoLayer]; 

AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition]; 


AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 
videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMake([imagesFilePath count] * [[albumSettings transitionTime] intValue] * 25, 25)); 

AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstruction]; 
videoCompositionInstruction.layerInstructions = [NSArray arrayWithObject:layerInstruction]; 

videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:wrapLayer]; 
videoComposition.frameDuration = CMTimeMake(1, 25); // 25 fps 
videoComposition.renderSize = CGSizeMake(1024, 768); 
videoComposition.instructions = [NSArray arrayWithObject:videoCompositionInstruction]; 

3) का दृष्टांत मैं पथ

दस्तावेज़ के लिए वीडियो निर्यात बनाने
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetLowQuality]; 
session.videoComposition = videoComposition; 

NSString *filePath = nil; 
filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
filePath = [filePath stringByAppendingPathComponent:@"Output.mov"];  

session.outputURL = [NSURL fileURLWithPath:filePath]; 
session.outputFileType = AVFileTypeQuickTimeMovie; 

[session exportAsynchronouslyWithCompletionHandler:^ 
{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     NSLog(@"Export Finished: %@", session.error); 
     if (session.error) { 
      [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL]; 
     } 
    }); 
}]; 

पर और एक यह त्रुटि प्राप्त निर्यात की:

निर्यात समाप्त: त्रुटि डोमेन = AVFoundationErrorDomain कोड = -11,822 "खोलें नहीं कर सकते" UserInfo = 0x49a97c0 {। NSLocalizedFailureReason = यह मीडिया प्रारूप समर्थित नहीं है, NSLocalizedDescription = खोलें नहीं कर सकते} AVErrorInvalidSourceMedia = -11,822,

AVErrorInvalidSourceMedia आपरेशन क्योंकि कुछ स्रोत मीडिया पढ़ा नहीं जा सका पूरी नहीं हो सकी:

मैं इसे अंदर प्रलेखन पाया।

मुझे पूरी तरह से यकीन है कि मेरे द्वारा निर्मित कोरएनीमेशन सही है क्योंकि मैंने इसे टेस्ट लेयर में प्रस्तुत किया है और मैं एनीमेशन प्रगति को सही ढंग से देख सकता हूं।

कोई भी मेरी समझ में मदद कर सकता है कि मेरी त्रुटि कहां है?

+0

कोशिश पोस्टिंग, या एक फाइल एक CALayer जोड़ने के लिए पूरी तरह से काले फ्रेम में शामिल है कि जरूरत है ऐप्पल के साथ बग रिपोर्ट। वे आपको बता सकते हैं कि आप क्या गलत कर रहे हैं। –

उत्तर

4

हो सकता है आप एक नकली फिल्म वीडियो परत को भरने, और फिर छवियों manpiulate को एप्पल डेवलपर मंचों पर

+0

यही वह है जो मैंने किया है। –

+0

वही यहाँ। अच्छी बात यह है कि आपको जिस चीज को करने की कोशिश कर रहे हैं उसकी लंबाई को भरने की आवश्यकता नहीं है। मैं 1 सेकंड का काला वीडियो (जो कि कैलियर द्वारा छुपा हुआ है) का उपयोग कर रहा हूं, लेकिन बहुत अधिक लंबाई निर्यात कर रहा हूं। – jpswain

+0

संक्रमण छवियों के साथ फिल्म के रूप में निर्यात छवियों के बारे में कोई विचार। मुझे पता है तो कृपया मुझे बताओ .. धन्यवाद। –

4

I found the AVVideoCompositionCoreAnimationTool class that have the ability to take a CoreAnimation and reencode it as a video

मेरे समझ है कि इस स्थान पर केवल CoreAnimation लेने के लिए और एक मौजूदा वीडियो में जोड़ने के लिए कर रहा था था। मैंने अभी दस्तावेज़ों की जांच की है, और उपलब्ध एकमात्र विधियों को भी एक वीडियो परत की आवश्यकता है।

संपादित करें: हाँ। दस्तावेज़ों और डब्ल्यूडब्ल्यूडीसी वीडियो में खुदाई, मुझे लगता है कि आपको इसके बजाय AVAssetWriter का उपयोग करना चाहिए, और लेखक को छवियां जोड़ना चाहिए। कुछ की तरह:

AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:somePath] fileType:AVFileTypeQuickTimeMovie error:&error]; 

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:320], AVVideoWidthKey, [NSNumber numberWithInt:480], AVVideoHeightKey, nil]; 
AVAssetWriterInput* writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain]; 

[videoWriter addInput:writerInput]; 

[videoWriter startWriting]; 
[videoWriter startSessionAtSourceTime:CMTimeMakeWithSeconds(0, 30)] 
[writerInput appendSampleBuffer:sampleBuffer]; 
[writerInput markAsFinished]; 
[videoWriter endSessionAtSourceTime:CMTimeMakeWithSeconds(60, 30)]; 
[videoWriter finishWriting]; 
+0

मुझे लगता है कि आप सही हैं। मैं इसमें और अधिक देखने वाला हूँ। मैं छवियों के अनुक्रम को बचाने की कोशिश कर रहा हूँ। – Franky

+0

'UIImage' या' CGImageRef 'लिखने के संदर्भ में,' नमूना बफर 'क्या है? सिर्फ कच्ची छवि पिक्सल? 'CMSampleBufferCreateForImageBuffer' के साथ बनाया गया? – bcattle

+0

@bcattle अपने प्रश्न को एक नए प्रश्न के रूप में पूछें, टिप्पणी नहीं। – Adam

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