cmp = [AVMutableComposition composition]; AVMutableCompositionTrack *vIDeoComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeVIDeo preferredTrackID:kCMPersistentTrackID_InvalID]; AVMutableCompositionTrack *audioComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_InvalID]; AVAssetTrack *sourceVIDeoTrack = [[asset tracksWithMediaType:AVMediaTypeVIDeo] objectAtIndex:0]; AVAssetTrack *sourceAudioTrack = [[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; [vIDeoComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero,[asset duration]) ofTrack:sourceVIDeoTrack atTime:kCMTimeZero error:nil] ; [audioComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero,[asset duration]) ofTrack:sourceAudioTrack atTime:kCMTimeZero error:nil]; animComp = [AVMutableVIDeoComposition vIDeoComposition]; animComp.renderSize = CGSizeMake(320,320); animComp.frameDuration = CMTimeMake(1,30); animComp.animationTool = [AVVIDeoCompositionCoreAnimationTool vIDeoCompositionCoreAnimationToolWithPostProcessingAsVIDeolayer:vIDeolayer inLayer:parentLayer]; // to gather the audio part of the vIDeo NSArray *tracksToDuck = [cmp tracksWithMediaType:AVMediaTypeAudio]; NSMutableArray *trackMixArray = [NSMutableArray array]; for (NSInteger i = 0; i < [tracksToDuck count]; i++) { AVMutableAudioMixinputParameters *trackMix = [AVMutableAudioMixinputParameters audioMixinputParametersWithTrack:[tracksToDuck objectAtIndex:i]]; [trackMix setVolume:5 atTime:kCMTimeZero]; [trackMixArray addobject:trackMix]; } audioMix = [AVMutableAudioMix audioMix]; audioMix.inputParameters = trackMixArray; AVMutableVIDeoCompositionInstruction *instruction = [AVMutableVIDeoCompositionInstruction vIDeoCompositionInstruction]; instruction.timeRange = CMTimeRangeMake(kCMTimeZero,[asset duration]); AVMutableVIDeoCompositionLayerInstruction *layerVIDeoInstruction = [AVMutableVIDeoCompositionLayerInstruction vIDeoCompositionLayerInstructionWithAssetTrack:vIDeoComposition]; [layerVIDeoInstruction setopacity:1.0 atTime:kCMTimeZero]; instruction.layerInstructions = [NSArray arrayWithObject:layerVIDeoInstruction] ; animComp.instructions = [NSArray arrayWithObject:instruction]; [self exportMovIE:self];
这是我导出视频的方法
-(IBAction) exportMovIE:(ID)sender{ //successCheck = NO; NSArray *docPaths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *tempPath = [docPaths objectAtIndex:0]; //NSLog(@"Temp Path: %@",tempPath); Nsstring *filename = [Nsstring stringWithFormat:@"%@/Final.MP4",tempPath]; NSfileManager *fileManager = [NSfileManager defaultManager] ; if([fileManager fileExistsAtPath:filename ]){ NSError *ferror = nil ; [fileManager removeItemAtPath:filename error:&ferror]; } NSURL *exportURL = [NSURL fileURLWithPath:filename]; AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:cmp presetname:AVAssetExportPresetMediumQuality] ; exporter.outputURL = exportURL; exporter.vIDeoComposition = animComp; //exporter.audioMix = audioMix; exporter.outputfileType = AVfileTypeQuickTimeMovIE; [exporter exportAsynchronouslyWithCompletionHandler:^(voID){ switch (exporter.status) { case AVAssetExportSessionStatusFailed:{ NSLog(@"Fail"); break; } case AVAssetExportSessionStatusCompleted:{ NSLog(@"Success vIDeo"); }); break; } default: break; } }]; NSLog(@"outsIDe");}解决方法 有一个出口的属性给出时间范围,尝试给时间范围少于实际时间(少几纳秒) 总结
以上是内存溢出为你收集整理的xcode – AvMutableComposition在最后发出黑框全部内容,希望文章能够帮你解决xcode – AvMutableComposition在最后发出黑框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)