से चलते समय AVMutableComposition में प्रकट नहीं होता है संपादित करें: अजीब चीज: ऐसा लगता है कि एक पूर्ण ऐप से यह कोड चलाने पर सब कुछ काम करता है, लेकिन मैं हमेशा से फिल्म का निर्माण चला रहा था इकाई परीक्षण, और केवल वहां काम नहीं किया। यह पता लगाने की कोशिश कर रहा है कि क्यों है ...CATextLayer एक इकाई परीक्षण
मैं AVMutableComposition का उपयोग करके वीडियो + ऑडियो + टेक्स्ट को गठबंधन करने और इसे एक नए वीडियो में निर्यात करने की कोशिश कर रहा हूं।
मेरे कोड WWDC '10
से AVEditDemo पर आधारित है मैं जोड़ा CATextLayer करने के लिए एक बैंगनी पृष्ठभूमि तो मैं एक तथ्य यह फिल्म करने के लिए निर्यात किया जाता है के लिए पता कर सकते हैं, लेकिन कोई पाठ दिखाया गया है ... मैं विभिन्न फोंट, स्थिति, रंग परिभाषाओं के साथ खेलने की कोशिश की, लेकिन कुछ भी मदद नहीं की, इसलिए मैंने यहां कोड पोस्ट करने का फैसला किया और देखा कि क्या कोई भी इसी तरह से ठोकर खा रहा है और मुझे बता सकता है कि मैं क्या खो रहा हूं।
यहाँ कोड (self.audio और self.video AVURLAssets कर रहे हैं) है:
CMTime exportDuration = self.audio.duration;
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *videoTrack = [[self.video tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// add the video in loop until the audio ends
CMTime currStartTime = kCMTimeZero;
while (CMTimeCompare(currStartTime, exportDuration) < 0) {
CMTime timeRemaining = CMTimeSubtract(exportDuration, currStartTime);
CMTime currLoopDuration = self.video.duration;
if (CMTimeCompare(currLoopDuration, timeRemaining) > 0) {
currLoopDuration = timeRemaining;
}
CMTimeRange currLoopTimeRange = CMTimeRangeMake(kCMTimeZero, currLoopDuration);
[compositionVideoTrack insertTimeRange:currLoopTimeRange ofTrack:videoTrack
atTime:currStartTime error:nil];
currStartTime = CMTimeAdd(currStartTime, currLoopDuration);
}
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *audioTrack = [self.audio.tracks objectAtIndex:0];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.audio.duration) ofTrack:audioTrack atTime:kCMTimeZero error:nil];
AVMutableVideoComposition *videoComposition;
// the text layer part - THIS IS THE PART THAT DOESN'T WORK WELL
CALayer *animatedTitleLayer = [CALayer layer];
CATextLayer *titleLayer = [[CATextLayer alloc] init];
titleLayer.string = @"asdfasdf";
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(0, 0, self.video.naturalSize.width/2, self.video.naturalSize.height/2);
titleLayer.opacity = 1.0;
titleLayer.backgroundColor = [UIColor purpleColor].CGColor;
[animatedTitleLayer addSublayer:titleLayer];
animatedTitleLayer.position = CGPointMake(self.video.naturalSize.width/2.0, self.video.naturalSize.height/2.0);
// build a Core Animation tree that contains both the animated title and the video.
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, self.video.naturalSize.width, self.video.naturalSize.height);
videoLayer.frame = CGRectMake(0, 0, self.video.naturalSize.width, self.video.naturalSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:animatedTitleLayer];
videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
AVMutableVideoCompositionInstruction *passThroughInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
passThroughInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, exportDuration);
AVMutableVideoCompositionLayerInstruction *passThroughLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];
passThroughInstruction.layerInstructions = [NSArray arrayWithObject:passThroughLayer];
videoComposition.instructions = [NSArray arrayWithObject:passThroughInstruction];
videoComposition.frameDuration = CMTimeMake(1, 30);
videoComposition.renderSize = self.video.naturalSize;
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
exportSession.videoComposition = videoComposition;
exportSession.outputURL = [NSURL fileURLWithPath:self.outputFilePath];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^() {
// save the video ...
}];
मुझे यकीन नहीं है .. यह मदद कर सकता है .. http://stackoverflow.com/questions/7205820/iphone-watermark-on-recorded-video –
धन्यवाद, मैं कुछ भी उतना ही कर रहा हूं वहां क्या उल्लेख किया गया है। अगर कोई मेरे कोड और प्रासंगिक उत्तर में एक महत्वपूर्ण अंतर को स्पॉट करता है तो मैं बहुत आभारी हूं। – yonix
क्या आपने फ़ॉन्ट आकार सेट करने का प्रयास किया है? –